perf: use terser for service worker too (#816)

This commit is contained in:
Nolan Lawson 2018-12-15 17:36:36 -08:00 committed by GitHub
parent 260f6acf0e
commit 3a335a9f4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 19 deletions

View file

@ -2,8 +2,7 @@ const webpack = require('webpack')
const config = require('sapper/config/webpack.js') const config = require('sapper/config/webpack.js')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin') const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin') const terser = require('./terser.config')
const isDev = process.env.NODE_ENV === 'development' const isDev = process.env.NODE_ENV === 'development'
module.exports = { module.exports = {
@ -35,22 +34,7 @@ module.exports = {
}, },
optimization: isDev ? {} : { optimization: isDev ? {} : {
minimizer: [ minimizer: [
new TerserWebpackPlugin({ terser()
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
ecma: 6,
mangle: true,
compress: {
pure_funcs: ['console.log']
},
output: {
comments: false
},
safari10: true
}
})
], ],
splitChunks: { splitChunks: {
chunks: 'async', chunks: 'async',

View file

@ -1,4 +1,5 @@
const config = require('sapper/config/webpack.js') const config = require('sapper/config/webpack.js')
const terser = require('./terser.config')
const webpack = require('webpack') const webpack = require('webpack')
const isDev = config.dev const isDev = config.dev
@ -10,7 +11,10 @@ module.exports = {
devtool: isDev ? 'inline-source-map' : 'source-map', devtool: isDev ? 'inline-source-map' : 'source-map',
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.browser': true,
'process.env.NODE_ENV': '"production"',
'process.env.SAPPER_TIMESTAMP': process.env.SAPPER_TIMESTAMP || Date.now() 'process.env.SAPPER_TIMESTAMP': process.env.SAPPER_TIMESTAMP || Date.now()
}) }),
terser()
] ]
} }

18
webpack/terser.config.js Normal file
View file

@ -0,0 +1,18 @@
const TerserWebpackPlugin = require('terser-webpack-plugin')
module.exports = () => new TerserWebpackPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
ecma: 6,
mangle: true,
compress: {
pure_funcs: ['console.log']
},
output: {
comments: false
},
safari10: true
}
})