M
M
markmariner2017-03-10 16:40:35
JavaScript
markmariner, 2017-03-10 16:40:35

How to minify code and js libraries with webpack?

My project is built with Webpack and uses about 20 npm libraries, including big ones like Angular.js. You need to minify the code to release the product. I understand that it is worth using a plugin for this webpack.optimize.UglifyJsPlugin, however, several questions arise:

  • Do I need to minify the connected libraries with this plugin or immediately connect their minified versions?
  • If I include minified versions, then how do I tell the plugin that there is no need to touch the libraries at all, but that it is enough just to minify my code?

I would be happy to hear reasoned opinions on these issues.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xutesayor, 2017-03-10
@xutesayor

Of course, you need to minify everything, because libraries are also not minified. Moreover, you need to minify only before deploying to production. I have it done like this:

if (process.env.NODE_ENV === 'production') {
    plugins.push(new webpack.optimize.UglifyJsPlugin({compressor: {warnings: false}}));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question