Skip to content

Instantly share code, notes, and snippets.

@dekadentno
Created March 15, 2019 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekadentno/19dd2775cd21eac868432a85125fa152 to your computer and use it in GitHub Desktop.
Save dekadentno/19dd2775cd21eac868432a85125fa152 to your computer and use it in GitHub Desktop.
vue config example working with purge css and terser (uglify / uglifyjs)
/**
npm i --save-dev terser-webpack-plugin purgecss @fullhuman/postcss-purgecss purgecss-webpack-plugin glob-all path
*/
const TerserPlugin = require('terser-webpack-plugin')
const PurgecssPlugin = require('purgecss-webpack-plugin')
const glob = require('glob-all') // required for purgecss
const path = require('path') // re quired for purgecss
...
configureWebpack() {
let additionalConfig = {};
if (process.env.NODE_ENV === 'production'){
additionalConfig = {
module: {
exprContextCritical: false
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
warnings: false,
compress: {
drop_console: true
}
}
}),
],
splitChunks: {
chunks: 'all'
}
},
plugins: [
new PurgecssPlugin({
paths: glob.sync([
path.join(__dirname, './public/index.html'),
path.join(__dirname, './src/**/*.vue'),
path.join(__dirname, './src/**/*.html')
])
})
]
};
} else {
// dev environment
additionalConfig = {
module: {
exprContextCritical: false
},
optimization: {
splitChunks: {
chunks: 'all'
}
}
};
}
return additionalConfig
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment