webpack.web.config.js 3.2 KB

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