webpack.config.js 804 B

123456789101112131415161718192021222324252627282930313233
  1. const { resolve } = require("path");
  2. //html资源处理
  3. const HtmlWebpackPlugin = require('html-webpack-plugin')
  4. //设置node环境变量 postcss-loader会根据它读取package.js里的browserslist配置
  5. process.env.NODE_ENV = 'development'
  6. /**
  7. *
  8. */
  9. module.exports = {
  10. entry:'./src/js/index.js',
  11. output: {
  12. // name取文件名
  13. filename: 'js/[name].[contenthash:10].js',
  14. path: resolve(__dirname, 'build')
  15. },
  16. plugins:[
  17. new HtmlWebpackPlugin({
  18. template: './src/index.html',
  19. minify:{
  20. collapseWhitespace:true,
  21. removeComments:true
  22. }
  23. })
  24. ],
  25. optimization:{
  26. splitChunks:{
  27. chunks:'all'
  28. }
  29. },
  30. mode:'production'
  31. }