webpack.config.prod.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict'
  2. const webpack = require('webpack')
  3. const CopyWebpackPlugin = require('copy-webpack-plugin')
  4. const merge = require('webpack-merge')
  5. const baseConfig = require('./webpack.config.base')
  6. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  7. const utils = require('./utils')
  8. const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
  9. // ERROR in vendor.js from UglifyJs
  10. // RangeError: Maximum call stack size exceeded
  11. module.exports = merge(baseConfig, {
  12. mode: 'production',
  13. // resolve: {
  14. // alias: {
  15. // 'static': utils.resolve('static')
  16. // }
  17. // },
  18. output: {
  19. publicPath: '/'
  20. },
  21. optimization: {
  22. minimize: true,
  23. minimizer: [
  24. new UglifyJSPlugin({
  25. uglifyOptions: {
  26. // Eliminate comments
  27. comments: false,
  28. // remove warnings
  29. // warnings: false,
  30. minimize: false,
  31. mangle: false,
  32. compress: {
  33. // Drop console statements
  34. drop_console: true,
  35. }
  36. }
  37. })
  38. ],
  39. splitChunks: {
  40. cacheGroups: {
  41. commons: {
  42. test: /[\\/]node_modules[\\/]/,
  43. name: "vendor",
  44. chunks: "all",
  45. }
  46. }
  47. }
  48. },
  49. module: {
  50. rules: [
  51. {
  52. test: /\.css?$/,
  53. use: [
  54. MiniCssExtractPlugin.loader,
  55. 'css-loader'
  56. ]
  57. }, {
  58. test: /\.scss$/,
  59. use: [
  60. MiniCssExtractPlugin.loader,
  61. 'css-loader',
  62. 'sass-loader'
  63. ]
  64. }
  65. ]
  66. },
  67. plugins: [
  68. new MiniCssExtractPlugin({
  69. filename: 'main.css'
  70. }),
  71. new webpack.DefinePlugin({
  72. "process.env": "'prod'"
  73. }),
  74. new CopyWebpackPlugin([{
  75. from: utils.resolve('static/.htaccess'),
  76. to: utils.resolve('dist/.htaccess'),
  77. toType: 'file'
  78. }])
  79. ]
  80. })