Created
March 15, 2019 10:00
-
-
Save dekadentno/19dd2775cd21eac868432a85125fa152 to your computer and use it in GitHub Desktop.
vue config example working with purge css and terser (uglify / uglifyjs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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