You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: /\.scss$/,
  19. use: ['vue-style-loader', 'css-loader', 'sass-loader']
  20. },
  21. {
  22. test: /\.sass$/,
  23. use: ['vue-style-loader', 'css-loader', 'sass-loader?indentedSyntax']
  24. },
  25. {
  26. test: /\.less$/,
  27. use: ['vue-style-loader', 'css-loader', 'less-loader']
  28. },
  29. {
  30. test: /\.css$/,
  31. use: ['vue-style-loader', 'css-loader']
  32. },
  33. {
  34. test: /\.html$/,
  35. use: 'vue-html-loader'
  36. },
  37. {
  38. test: /\.js$/,
  39. use: 'babel-loader',
  40. include: [ path.resolve(__dirname, '../src/renderer') ],
  41. exclude: /node_modules/
  42. },
  43. {
  44. test: /\.vue$/,
  45. use: {
  46. loader: 'vue-loader',
  47. options: {
  48. extractCSS: true,
  49. loaders: {
  50. sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
  51. scss: 'vue-style-loader!css-loader!sass-loader',
  52. less: 'vue-style-loader!css-loader!less-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 VueLoaderPlugin(),
  81. new MiniCssExtractPlugin({filename: 'styles.css'}),
  82. new HtmlWebpackPlugin({
  83. filename: 'index.html',
  84. template: path.resolve(__dirname, '../src/index.ejs'),
  85. templateParameters(compilation, assets, options) {
  86. return {
  87. compilation: compilation,
  88. webpack: compilation.getStats().toJson(),
  89. webpackConfig: compilation.options,
  90. htmlWebpackPlugin: {
  91. files: assets,
  92. options: options
  93. },
  94. process,
  95. };
  96. },
  97. minify: {
  98. collapseWhitespace: true,
  99. removeAttributeQuotes: true,
  100. removeComments: true
  101. },
  102. nodeModules: false
  103. }),
  104. new webpack.DefinePlugin({
  105. 'process.env.IS_WEB': 'true'
  106. }),
  107. new webpack.HotModuleReplacementPlugin(),
  108. new webpack.NoEmitOnErrorsPlugin()
  109. ],
  110. output: {
  111. filename: '[name].js',
  112. path: path.join(__dirname, '../dist/web')
  113. },
  114. resolve: {
  115. alias: {
  116. '@': path.join(__dirname, '../src/renderer'),
  117. 'vue$': 'vue/dist/vue.esm.js'
  118. },
  119. extensions: ['.js', '.vue', '.json', '.css']
  120. },
  121. target: 'web'
  122. }
  123. /**
  124. * Adjust webConfig for production settings
  125. */
  126. if (process.env.NODE_ENV === 'production') {
  127. webConfig.devtool = ''
  128. webConfig.plugins.push(
  129. new MinifyPlugin(),
  130. new CopyWebpackPlugin([
  131. {
  132. from: path.join(__dirname, '../static'),
  133. to: path.join(__dirname, '../dist/web/static'),
  134. ignore: ['.*']
  135. }
  136. ]),
  137. new webpack.DefinePlugin({
  138. 'process.env.NODE_ENV': '"production"'
  139. }),
  140. new webpack.LoaderOptionsPlugin({
  141. minimize: true
  142. })
  143. )
  144. }
  145. module.exports = webConfig