webpack.demo.build.conf.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const webpack = require('webpack');
  2. const baseConf = require('./webpack.demo.base.conf.js');
  3. const merge = require('webpack-merge');
  4. const path = require('path');
  5. const CopyWebpackPlugin = require('copy-webpack-plugin');
  6. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  7. const OfflinePlugin = require('offline-plugin');
  8. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  9. const rimraf = require('rimraf');
  10. rimraf('./dist/sites/demo', function (err) {
  11. if(err) console.log(err);
  12. });
  13. rimraf('./dist/sites/demo.html', function (err) {
  14. if (err) console.log(err);
  15. });
  16. module.exports = merge(baseConf, {
  17. mode: 'production',
  18. devtool: 'cheap-module-source-map',
  19. plugins: [
  20. new webpack.DefinePlugin({
  21. 'process.env': {
  22. NODE_ENV: '"production"'
  23. }
  24. }),
  25. new CopyWebpackPlugin([
  26. { from: path.join(__dirname, "../sites/demo/asset/img/favicon.ico"), to: path.join(__dirname, "../dist/sites/")}
  27. ]),
  28. new CopyWebpackPlugin([
  29. { from: path.join(__dirname, "../sites/demo/asset/img/pwa_logo.png"), to: path.join(__dirname, "../dist/sites/img/") }
  30. ]),
  31. new CopyWebpackPlugin([
  32. { from: path.join(__dirname, "../sites/demo/asset/manifest.json"), to: path.join(__dirname, "../dist/sites/demo/") }
  33. ]),
  34. new OfflinePlugin({
  35. ServiceWorker: {
  36. events: true
  37. }
  38. })
  39. ],
  40. optimization: {
  41. minimizer: [
  42. new UglifyJsPlugin({
  43. uglifyOptions: {
  44. compress: {
  45. warnings: false
  46. }
  47. },
  48. sourceMap: false,
  49. parallel: true
  50. }),
  51. new OptimizeCSSAssetsPlugin({})
  52. ]
  53. },
  54. });