webpack.prod.conf.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. devtool: 'source-map',
  14. module: {
  15. rules: [
  16. {
  17. test: /\.(sa|sc|c)ss$/,
  18. use: [
  19. {
  20. loader: MiniCssExtractPlugin.loader,
  21. options: {
  22. publicPath: '../'
  23. }
  24. },
  25. 'css-loader',
  26. 'postcss-loader',
  27. 'sass-loader',
  28. ],
  29. },
  30. {
  31. test: /\.less$/,
  32. use: [
  33. {
  34. loader: MiniCssExtractPlugin.loader,
  35. options: {
  36. publicPath: '../'
  37. }
  38. },
  39. 'css-loader',
  40. 'postcss-loader',
  41. 'less-loader',
  42. ],
  43. }
  44. ]
  45. },
  46. plugins: [
  47. new CleanWebpackPlugin(),
  48. new MiniCssExtractPlugin({
  49. filename: "css/[name].css",
  50. chunkFilename: "css/[id].css"
  51. }),
  52. new webpack.DefinePlugin({
  53. 'process.env': require('../config/prod.env')
  54. }), // 配置请求地址
  55. ]
  56. })