webpack.web.config.js 4.0 KB

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