webpack.prod.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const webpack = require('webpack')
  2. const merge = require('webpack-merge')
  3. const CleanWebpackPlugin = require('clean-webpack-plugin')
  4. const OfflinePlugin = require('offline-plugin')
  5. const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin')
  6. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
  7. const common = require('./webpack.common.js')
  8. module.exports = merge(common, {
  9. mode: 'production',
  10. module: {
  11. rules: []
  12. },
  13. plugins: [
  14. new SimpleProgressWebpackPlugin({
  15. format: 'expanded'
  16. }),
  17. new CleanWebpackPlugin([
  18. 'assets/js/*.*',
  19. 'assets/css/*.*',
  20. 'assets/*.js',
  21. 'assets/*.json'
  22. ], {
  23. root: process.cwd(),
  24. verbose: false
  25. }),
  26. new webpack.DefinePlugin({
  27. 'process.env.NODE_ENV': JSON.stringify('production')
  28. }),
  29. new OptimizeCssAssetsPlugin({
  30. cssProcessorOptions: { discardComments: { removeAll: true } },
  31. canPrint: true
  32. }),
  33. new OfflinePlugin({
  34. ServiceWorker: {
  35. minify: false
  36. },
  37. publicPath: '/',
  38. externals: ['/'],
  39. caches: {
  40. main: [
  41. 'js/client.js'
  42. ],
  43. additional: [
  44. ':externals:'
  45. ],
  46. optional: [
  47. 'js/*.chunk.js'
  48. ]
  49. },
  50. safeToUseOptionalCaches: true
  51. })
  52. ]
  53. })