webpack.prod.conf.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. output: {
  14. publicPath: './'
  15. },
  16. module:{
  17. rules: [
  18. {
  19. test: /\.(c|le)ss$/,
  20. use: [
  21. MiniCssExtractPlugin.loader,
  22. 'css-loader',
  23. 'less-loader'
  24. ]
  25. }
  26. ]
  27. },
  28. plugins: [
  29. new CleanWebpackPlugin(),
  30. new OptimizeCSSAssetsPlugin(),
  31. new MiniCssExtractPlugin({
  32. filename: "css/[name].css",
  33. chunkFilename: "css/[id].css"
  34. }),
  35. new webpack.DefinePlugin({
  36. 'process.env': require('../config/prod.env')
  37. }), // 配置请求地址
  38. ]
  39. })