webpack.prod.conf.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // 存放prod配置
  2. const merge = require('webpack-merge');
  3. const baseConfig = require('./webpack.base.conf');
  4. const path = require('path');
  5. const webpack = require('webpack');
  6. // 清除打包多余文件
  7. const CleanWebpackPlugin = require('clean-webpack-plugin');
  8. // 分离css,打包到单独文件
  9. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  10. // 压缩css
  11. const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
  12. module.exports = merge(baseConfig, {
  13. mode: "production",
  14. devtool: 'source-map',
  15. module: {
  16. rules: [
  17. {
  18. test: /\.(sa|sc|c)ss$/,
  19. use: [
  20. {
  21. loader: MiniCssExtractPlugin.loader,
  22. options: {
  23. publicPath: '../'
  24. }
  25. },
  26. 'css-loader',
  27. 'postcss-loader',
  28. 'sass-loader',
  29. ],
  30. },
  31. {
  32. test: /\.less$/,
  33. use: [
  34. {
  35. loader: MiniCssExtractPlugin.loader,
  36. options: {
  37. publicPath: '../'
  38. }
  39. },
  40. 'css-loader',
  41. 'postcss-loader',
  42. 'less-loader',
  43. ],
  44. }
  45. ]
  46. },
  47. plugins: [
  48. new CleanWebpackPlugin(),
  49. new MiniCssExtractPlugin({
  50. filename: "css/[name].css",
  51. chunkFilename: "css/[id].css"
  52. }),
  53. new webpack.DefinePlugin({
  54. 'process.env': require('../config/prod.env')
  55. }), // 配置请求地址
  56. ]
  57. })