123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- "use strict";
- const path = require("path");
- const TerserPlugin = require('terser-webpack-plugin')
- const CompressionWebpackPlugin = require('compression-webpack-plugin')
- const isProduction = process.env.NODE_ENV !== 'development'
- function resolve (dir) {
- return path.join(__dirname, dir);
- }
- console.log(process.env)
- module.exports = {
- productionSourceMap: false,
- lintOnSave: false,
- configureWebpack: {
- output: {
- filename: `[name].${new Date().getTime()}.js`,
- chunkFilename: `[name].${new Date().getTime()}.js`
- }
- },
- chainWebpack: config => {
-
- config.module
- .rule("svg")
- .exclude.add(resolve("src/icons"))
- .end();
- config.module
- .rule("icons")
- .test(/\.svg$/)
- .include.add(resolve("src/icons"))
- .end()
- .use("svg-sprite-loader")
- .loader("svg-sprite-loader")
- .options({
- symbolId: "icon-[name]"
- })
- .end();
-
- if (isProduction) {
-
- config.plugins.delete('preload');
- config.plugins.delete('prefetch');
-
- config.optimization.minimize(true);
-
- config.optimization.splitChunks({
- chunks: 'all'
- })
- }
- },
- configureWebpack: config => {
-
- if (isProduction) {
-
- config.plugins.push(
- new TerserPlugin({
- terserOptions: {
-
- compress: {
- warnings: false,
- drop_debugger: true,
- drop_console: true,
- pure_funcs: ['console.log']
- }
- },
- sourceMap: false,
- parallel: true
- })
- )
-
- const productionGzipExtensions = ['html', 'js', 'css']
- config.plugins.push(
- new CompressionWebpackPlugin({
- filename: '[path].gz[query]',
- algorithm: 'gzip',
- test: new RegExp(
- '\\.(' + productionGzipExtensions.join('|') + ')$'
- ),
- threshold: 10240,
- minRatio: 0.8,
- deleteOriginalAssets: false
- })
- )
-
- config.optimization = {
- splitChunks: {
- cacheGroups: {
- vendor: {
- chunks: 'all',
- test: /node_modules/,
- name: 'vendor',
- minChunks: 1,
- maxInitialRequests: 5,
- minSize: 0,
- priority: 100
- },
- common: {
- chunks: 'all',
- test: /[\\/]src[\\/]js[\\/]/,
- name: 'common',
- minChunks: 2,
- maxInitialRequests: 5,
- minSize: 0,
- priority: 60
- },
- styles: {
- name: 'styles',
- test: /\.(sa|sc|c)ss$/,
- chunks: 'all',
- enforce: true
- },
- runtimeChunk: {
- name: 'manifest'
- }
- }
- }
- }
- }
- }
- };
|