Solution to WebPack packages Slow Summary Summary

Just started with WebPack, talk about the problem of solving the problem of Webpack bags

Tips 1

Webpack is always the first time when packing Do a long ready, including loading plugins. When you just get in touching WebPack – test – change – WebPack, this way, Many people have collapsed the WebPack is not easy. In fact, this is a wrong way of use.

The correct way should perform WebPack -Watch so WebPack will be automatically compiled. When the first time is really slow, but the automatic compilation will be much faster, and the package time is twice. .

Webpack cooperates React, jQuery some copies of libraries, although not writing a few lines of code but finding that I rely on the file a few M. . Can you not let these share a library into our file?

EXTERNALS: {‘ANTD’: TRUE, ‘React’: ‘React’, ‘React-Dom’: ‘ReactDom’}
These content is coupled to the root of the WebPack configuration file. Tell WebPack Don’t go to load the module when Require (“react”), go directly (it is not very clear here, some say “:” is Window.react, write it, you can use it directly without requirring, after being determined Replenishment, generally write TRUE), of course, this way to manually introduce JS files in the HTML entry:

      Try the regquire ("React") in the project, will not be hit, the file is changed to a few K, suddenly feeling this thing is still available.    
In most cases, it is already possible to get most of the problems, but when using MaterialiAlui, click the event to always report an error. Probably meaningful introduction of Reacting. If this problem occurs, please use the skill 3. Put those common modules in another file, then use the CommonschunkPlugin plug-in, you will not repeat another file when WebPack -watch is non-first-package.

Entry: {// This is my own file, changed to my own main: ‘./apps/main.jsx’, // this is the outside The thing is packaged into common.js’ common ‘: [‘ ./ node_modules / react / dist / react-with-addons.min.js’, ‘. / Node_modules / react-dom / dist / react-dom.min.js ‘]}, Plugins: [// Turn Common.js to a common, unpacking new webpack.Optimize.commonschunkplugin (‘ Common ‘,’ Common.js’)] OUTPUT in addition to the first pass package. {path: path.resolve (ContainerPath, ‘Dist /’), filename: ‘[name] .js’}

adds these content on the root of the WebPack configuration file Need to introduce common.js
[1 in the HTML entrance23] // Confirm that this file has been there after the first time
This The way is still very slow after WebPack -watch (because you want to play CommON), you will not play COMMON again. And there is an advantage that you don’t have to quit the React, jQuery, only one of the CommON is OK.

The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment