Advertisement
Guest User

Untitled

a guest
Aug 15th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. 'use strict';
  2.  
  3. const webpack = require('webpack');
  4. const merge = require('webpack-merge');
  5. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  6. const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
  7. const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
  8. const CompressionPlugin = require('compression-webpack-plugin');
  9. const helpers = require('./helpers');
  10. const commonConfig = require('./webpack.config.common');
  11. const isProd = process.env.NODE_ENV === 'production';
  12. const environment = isProd ? require('./env/prod.env') : require('./env/staging.env');
  13. const ManifestPlugin = require('webpack-manifest-plugin');
  14.  
  15. const webpackConfig = merge(commonConfig, {
  16. mode: 'production',
  17. output: {
  18. path: helpers.root('public'),
  19. publicPath: '/',
  20. filename: 'js/[hash].js',
  21. chunkFilename: 'js/[id].[hash].chunk.js'
  22. },
  23. optimization: {
  24. runtimeChunk: 'single',
  25. minimizer: [
  26. new OptimizeCSSAssetsPlugin({
  27. cssProcessorPluginOptions: {
  28. preset: [ 'default', { discardComments: { removeAll: true } } ],
  29. }
  30. }),
  31. new UglifyJSPlugin({
  32. cache: true,
  33. parallel: true,
  34. sourceMap: !isProd
  35. })
  36. ],
  37. splitChunks: {
  38. chunks: 'async',
  39. minSize: 30000,
  40. maxSize: 0,
  41. minChunks: 1,
  42. maxAsyncRequests: 5,
  43. maxInitialRequests: 3,
  44. automaticNameDelimiter: '~',
  45. automaticNameMaxLength: 30,
  46. cacheGroups: {
  47. vendor: {
  48. test: /[\\/]node_modules[\\/]/,
  49. name (module) {
  50. const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
  51. return `npm.${packageName.replace('@', '')}`;
  52. }
  53. },
  54. styles: {
  55. test: /\.css$/,
  56. name: 'styles',
  57. chunks: 'all',
  58. enforce: true
  59. }
  60. }
  61. }
  62. },
  63. plugins: [
  64. new webpack.EnvironmentPlugin(environment),
  65. new MiniCSSExtractPlugin({
  66. filename: 'css/[name].[hash].css',
  67. chunkFilename: 'css/[id].[hash].css'
  68. }),
  69. new CompressionPlugin({
  70. filename: '[path].gz[query]',
  71. algorithm: 'gzip',
  72. test: new RegExp('\\.(js|css)$'),
  73. threshold: 10240,
  74. minRatio: 0.8
  75. }),
  76. new webpack.HashedModuleIdsPlugin(),
  77. new ManifestPlugin(),
  78. ]
  79. });
  80.  
  81. if (!isProd) {
  82. webpackConfig.devtool = 'source-map';
  83.  
  84. if (process.env.npm_config_report) {
  85. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  86. webpackConfig.plugins.push(new BundleAnalyzerPlugin());
  87. }
  88. }
  89.  
  90. module.exports = webpackConfig;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement