webpack.web.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. minify: {
  86. collapseWhitespace: true,
  87. removeAttributeQuotes: true,
  88. removeComments: true
  89. },
  90. nodeModules: false
  91. }),
  92. new webpack.DefinePlugin({
  93. 'process.env.IS_WEB': 'true'
  94. }),
  95. new webpack.HotModuleReplacementPlugin(),
  96. new webpack.NoEmitOnErrorsPlugin()
  97. ],
  98. output: {
  99. filename: '[name].js',
  100. path: path.join(__dirname, '../dist/web')
  101. },
  102. resolve: {
  103. alias: {
  104. '@': path.join(__dirname, '../src/renderer'),
  105. 'vue$': 'vue/dist/vue.esm.js'
  106. },
  107. extensions: ['.js', '.vue', '.json', '.css']
  108. },
  109. target: 'web'
  110. }
  111. /**
  112. * Adjust webConfig for production settings
  113. */
  114. if (process.env.NODE_ENV === 'production') {
  115. webConfig.devtool = ''
  116. webConfig.plugins.push(
  117. new MinifyPlugin(),
  118. new CopyWebpackPlugin([
  119. {
  120. from: path.join(__dirname, '../static'),
  121. to: path.join(__dirname, '../dist/web/static'),
  122. ignore: ['.*']
  123. }
  124. ]),
  125. new webpack.DefinePlugin({
  126. 'process.env.NODE_ENV': '"production"'
  127. }),
  128. new webpack.LoaderOptionsPlugin({
  129. minimize: true
  130. })
  131. )
  132. }
  133. module.exports = webConfig