Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const webpack = require('webpack');
- const merge = require('webpack-merge');
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
- const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
- const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
- const CompressionPlugin = require('compression-webpack-plugin');
- const helpers = require('./helpers');
- const commonConfig = require('./webpack.config.common');
- const isProd = process.env.NODE_ENV === 'production';
- const environment = isProd ? require('./env/prod.env') : require('./env/staging.env');
- const ManifestPlugin = require('webpack-manifest-plugin');
- const webpackConfig = merge(commonConfig, {
- mode: 'production',
- output: {
- path: helpers.root('public'),
- publicPath: '/',
- filename: 'js/[hash].js',
- chunkFilename: 'js/[id].[hash].chunk.js'
- },
- optimization: {
- runtimeChunk: 'single',
- minimizer: [
- new OptimizeCSSAssetsPlugin({
- cssProcessorPluginOptions: {
- preset: [ 'default', { discardComments: { removeAll: true } } ],
- }
- }),
- new UglifyJSPlugin({
- cache: true,
- parallel: true,
- sourceMap: !isProd
- })
- ],
- splitChunks: {
- chunks: 'async',
- minSize: 30000,
- maxSize: 0,
- minChunks: 1,
- maxAsyncRequests: 5,
- maxInitialRequests: 3,
- automaticNameDelimiter: '~',
- automaticNameMaxLength: 30,
- cacheGroups: {
- vendor: {
- test: /[\\/]node_modules[\\/]/,
- name (module) {
- const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
- return `npm.${packageName.replace('@', '')}`;
- }
- },
- styles: {
- test: /\.css$/,
- name: 'styles',
- chunks: 'all',
- enforce: true
- }
- }
- }
- },
- plugins: [
- new webpack.EnvironmentPlugin(environment),
- new MiniCSSExtractPlugin({
- filename: 'css/[name].[hash].css',
- chunkFilename: 'css/[id].[hash].css'
- }),
- new CompressionPlugin({
- filename: '[path].gz[query]',
- algorithm: 'gzip',
- test: new RegExp('\\.(js|css)$'),
- threshold: 10240,
- minRatio: 0.8
- }),
- new webpack.HashedModuleIdsPlugin(),
- new ManifestPlugin(),
- ]
- });
- if (!isProd) {
- webpackConfig.devtool = 'source-map';
- if (process.env.npm_config_report) {
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
- webpackConfig.plugins.push(new BundleAnalyzerPlugin());
- }
- }
- module.exports = webpackConfig;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement