To utilize Terser for minimizing JS files in Vue 2, follow these steps:
Install Terser as a dev dependency using the command npm install terser --save-dev
Create a vue.config.js
file in the root directory of your project
In the vue.config.js
file, add the following code:
module.exports = {
chainWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer('terser').tap(args => {
args[0].terserOptions.compress.drop_console = true
return args
})
}
}
}
The above code checks if the NODE_ENV is set to production and then applies Terser optimization. It also drops the console statements from the JS files.
Run the build command npm run build
and Terser will be utilized to minimize JS files in Vue 2.
Note: The vue.config.js
file is automatically loaded by Vue CLI, but if you have created your project from scratch without using Vue CLI, you need to specify the vue.config.js
file in your build process.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-19 12:43:05 +0000
Seen: 7 times
Last updated: Jun 19 '23
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?
When I attempt to generate a database, why does the azure-cosmos-emulator become unresponsive?
What steps can I take to prevent my webpage from slowing down when all parts of a div are displayed?