webpack.prod.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const merge = require('webpack-merge');
  2. const common = require('./webpack.common.config.js');
  3. const path = require('path');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  6. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  7. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  8. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  9. module.exports = merge(common, {
  10. module: {
  11. rules: [
  12. {
  13. test: /\.css$/,
  14. use: [
  15. MiniCssExtractPlugin.loader,
  16. 'css-loader'
  17. ]
  18. },
  19. {
  20. test: /\.less$/,
  21. use: [
  22. MiniCssExtractPlugin.loader,
  23. 'css-loader',
  24. 'less-loader'
  25. ]
  26. },
  27. {
  28. test: /\.(sass|scss)$/,
  29. use: [
  30. MiniCssExtractPlugin.loader,
  31. 'css-loader',
  32. 'sass-loader'
  33. ]
  34. },
  35. ]
  36. },
  37. optimization: {
  38. minimizer: [
  39. //new UglifyJsPlugin(),
  40. new OptimizeCssAssetsPlugin({
  41. assetNameRegExp:/\.css$/g,
  42. cssProcessor:require("cssnano"),
  43. cssProcessorPluginOptions:{
  44. preset:['default', { discardComments: { removeAll:true } }]
  45. },
  46. canPrint:true
  47. })
  48. ],
  49. splitChunks: {
  50. chunks: 'all',
  51. minSize: 30000,
  52. maxSize: 0,
  53. minChunks: 1,
  54. cacheGroups: {
  55. framework: {
  56. test: "framework",
  57. name: "framework",
  58. enforce: true
  59. },
  60. vendors: {
  61. priority: -10,
  62. test: /node_modules/,
  63. name: "vendor",
  64. enforce: true,
  65. },
  66. }
  67. }
  68. },
  69. mode: 'production',
  70. output: {
  71. filename: 'nodejs/[name].[hash].bundle.js',
  72. },
  73. mode: 'development',
  74. devServer: {
  75. host:'127.0.0.1',
  76. allowedHosts: [
  77. 'cld2.com'
  78. ],
  79. contentBase: path.resolve(__dirname, '../dist'),
  80. open: true,
  81. port: 9090,
  82. compress: true,
  83. hot: true,
  84. historyApiFallback: {
  85. rewrites: [
  86. {
  87. from: /^\/company/, to: '/',
  88. from: /^\/product\/lockStatistics/, to: '/product',
  89. from: /^\/product/, to: '/product',
  90. //客户相关
  91. from: /^\/contact/, to: '/contact',
  92. from: /^\/contact\/company/, to: '/contact',
  93. },
  94. ]
  95. }
  96. },
  97. plugins: [
  98. new HtmlWebpackPlugin({
  99. filename: 'index.html',
  100. template: 'public/index.html',
  101. chunks:['workbench','framework'],
  102. // inject: 'body',
  103. // minify: {
  104. // removeComments: true,
  105. // collapseWhitespace: true,
  106. // },
  107. }),
  108. new MiniCssExtractPlugin({
  109. filename: 'nodecss/[name].[hash].css',
  110. chunkFilename: 'css/[id].[hash].css',
  111. }),
  112. //new CleanWebpackPlugin(),
  113. ]
  114. });