webpack.web.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. 'use strict'
  2. process.env.BABEL_ENV = 'web'
  3. const path = require('path')
  4. const webpack = require('webpack')
  5. const BabiliWebpackPlugin = require('babili-webpack-plugin')
  6. const CopyWebpackPlugin = require('copy-webpack-plugin')
  7. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  8. const HtmlWebpackPlugin = require('html-webpack-plugin')
  9. let webConfig = {
  10. devtool: '#cheap-module-eval-source-map',
  11. entry: {
  12. web: path.join(__dirname, '../src/renderer/main.js')
  13. },
  14. module: {
  15. rules: [
  16. {
  17. test: /\.(js|vue)$/,
  18. enforce: 'pre',
  19. exclude: /node_modules/,
  20. use: {
  21. loader: 'eslint-loader',
  22. options: {
  23. formatter: require('eslint-friendly-formatter')
  24. }
  25. }
  26. },
  27. {
  28. test: /\.css$/,
  29. use: ExtractTextPlugin.extract({
  30. fallback: 'style-loader',
  31. use: 'css-loader'
  32. })
  33. },
  34. {
  35. test: /\.html$/,
  36. use: 'vue-html-loader'
  37. },
  38. {
  39. test: /\.js$/,
  40. use: 'babel-loader',
  41. include: [ path.resolve(__dirname, '../src/renderer') ],
  42. exclude: /node_modules/
  43. },
  44. {
  45. test: /\.vue$/,
  46. use: {
  47. loader: 'vue-loader',
  48. options: {
  49. extractCSS: true,
  50. loaders: {
  51. sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
  52. scss: 'vue-style-loader!css-loader!sass-loader'
  53. }
  54. }
  55. }
  56. },
  57. {
  58. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  59. use: {
  60. loader: 'url-loader',
  61. query: {
  62. limit: 10000,
  63. name: 'imgs/[name].[ext]'
  64. }
  65. }
  66. },
  67. {
  68. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  69. use: {
  70. loader: 'url-loader',
  71. query: {
  72. limit: 10000,
  73. name: 'fonts/[name].[ext]'
  74. }
  75. }
  76. }
  77. ]
  78. },
  79. plugins: [
  80. new ExtractTextPlugin('styles.css'),
  81. new HtmlWebpackPlugin({
  82. filename: 'index.html',
  83. template: path.resolve(__dirname, '../src/index.ejs'),
  84. minify: {
  85. collapseWhitespace: true,
  86. removeAttributeQuotes: true,
  87. removeComments: true
  88. },
  89. nodeModules: false
  90. }),
  91. new webpack.DefinePlugin({
  92. 'process.env.IS_WEB': 'true'
  93. }),
  94. new webpack.HotModuleReplacementPlugin(),
  95. new webpack.NoEmitOnErrorsPlugin()
  96. ],
  97. output: {
  98. filename: '[name].js',
  99. path: path.join(__dirname, '../dist/web')
  100. },
  101. resolve: {
  102. alias: {
  103. '@': path.join(__dirname, '../src/renderer'),
  104. 'vue$': 'vue/dist/vue.esm.js'
  105. },
  106. extensions: ['.js', '.vue', '.json', '.css']
  107. },
  108. target: 'web'
  109. }
  110. /**
  111. * Adjust webConfig for production settings
  112. */
  113. if (process.env.NODE_ENV === 'production') {
  114. webConfig.devtool = ''
  115. webConfig.plugins.push(
  116. new BabiliWebpackPlugin(),
  117. new CopyWebpackPlugin([
  118. {
  119. from: path.join(__dirname, '../static'),
  120. to: path.join(__dirname, '../dist/web/static'),
  121. ignore: ['.*']
  122. }
  123. ]),
  124. new webpack.DefinePlugin({
  125. 'process.env.NODE_ENV': '"production"'
  126. }),
  127. new webpack.LoaderOptionsPlugin({
  128. minimize: true
  129. })
  130. )
  131. }
  132. module.exports = webConfig