webpack.prod.conf.js 990 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var path = require('path');
  2. var merge = require('webpack-merge');
  3. var baseConfig = require('./webpack.base.conf');
  4. var webpack = require('webpack');
  5. // 清除打包多余文件
  6. const CleanWebpackPlugin = require('clean-webpack-plugin');
  7. // 分离css,打包到单独文件
  8. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  9. // 压缩css
  10. const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
  11. module.exports = merge(baseConfig, {
  12. mode: 'production',
  13. module:{
  14. rules: [
  15. {
  16. test: /\.(c|le)ss$/,
  17. use: [
  18. MiniCssExtractPlugin.loader,
  19. 'css-loader',
  20. 'less-loader'
  21. ]
  22. }
  23. ]
  24. },
  25. plugins: [
  26. new CleanWebpackPlugin(),
  27. new OptimizeCSSAssetsPlugin(),
  28. new MiniCssExtractPlugin({
  29. filename: "css/[name].css",
  30. chunkFilename: "css/[id].css"
  31. }),
  32. new webpack.DefinePlugin({
  33. 'process.env': require('../config/prod.env')
  34. }), // 配置请求地址
  35. ]
  36. })