webpack.web.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: /\.less$/,
  19. use: ['vue-style-loader', 'css-loader', 'less-loader']
  20. },
  21. {
  22. test: /\.css$/,
  23. use: ['vue-style-loader', 'css-loader']
  24. },
  25. {
  26. test: /\.html$/,
  27. use: 'vue-html-loader'
  28. },
  29. {
  30. test: /\.js$/,
  31. use: 'babel-loader',
  32. include: [ path.resolve(__dirname, '../src/renderer') ],
  33. exclude: /node_modules/
  34. },
  35. {
  36. test: /\.vue$/,
  37. use: {
  38. loader: 'vue-loader',
  39. options: {
  40. extractCSS: true,
  41. loaders: {
  42. sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
  43. scss: 'vue-style-loader!css-loader!sass-loader',
  44. less: 'vue-style-loader!css-loader!less-loader'
  45. }
  46. }
  47. }
  48. },
  49. {
  50. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  51. use: {
  52. loader: 'url-loader',
  53. query: {
  54. limit: 10000,
  55. name: 'imgs/[name].[ext]'
  56. }
  57. }
  58. },
  59. {
  60. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  61. use: {
  62. loader: 'url-loader',
  63. query: {
  64. limit: 10000,
  65. name: 'fonts/[name].[ext]'
  66. }
  67. }
  68. }
  69. ]
  70. },
  71. plugins: [
  72. new VueLoaderPlugin(),
  73. new MiniCssExtractPlugin({filename: 'styles.css'}),
  74. new HtmlWebpackPlugin({
  75. filename: 'index.html',
  76. template: path.resolve(__dirname, '../src/index.ejs'),
  77. templateParameters(compilation, assets, options) {
  78. return {
  79. compilation: compilation,
  80. webpack: compilation.getStats().toJson(),
  81. webpackConfig: compilation.options,
  82. htmlWebpackPlugin: {
  83. files: assets,
  84. options: options,
  85. },
  86. process,
  87. };
  88. },
  89. minify: {
  90. collapseWhitespace: true,
  91. removeAttributeQuotes: true,
  92. removeComments: true
  93. },
  94. nodeModules: false
  95. }),
  96. new webpack.DefinePlugin({
  97. 'process.env.IS_WEB': 'true'
  98. }),
  99. new webpack.HotModuleReplacementPlugin(),
  100. new webpack.NoEmitOnErrorsPlugin()
  101. ],
  102. output: {
  103. filename: '[name].js',
  104. path: path.join(__dirname, '../dist/web')
  105. },
  106. resolve: {
  107. alias: {
  108. '@': path.join(__dirname, '../src/renderer'),
  109. 'vue$': 'vue/dist/vue.esm.js'
  110. },
  111. extensions: ['.js', '.vue', '.json', '.css']
  112. },
  113. target: 'web'
  114. }
  115. /**
  116. * Adjust webConfig for production settings
  117. */
  118. if (process.env.NODE_ENV === 'production') {
  119. webConfig.devtool = ''
  120. webConfig.plugins.push(
  121. new MinifyPlugin(),
  122. new CopyWebpackPlugin([
  123. {
  124. from: path.join(__dirname, '../static'),
  125. to: path.join(__dirname, '../dist/web/static'),
  126. ignore: ['.*']
  127. }
  128. ]),
  129. new webpack.DefinePlugin({
  130. 'process.env.NODE_ENV': '"production"'
  131. }),
  132. new webpack.LoaderOptionsPlugin({
  133. minimize: true
  134. })
  135. )
  136. }
  137. module.exports = webConfig