5 Plugins Plug-in
5.1 Our Nodejs system is full of plug-ins, Webpack is also based on a variety of plug-ins to work properly, plug-ins for Webpack is a very important pillar to solve the loader can not achieve a lot of things.
Plug - ins:
A plug-in is a JavaScript object with the Apply property, where the Apply property is called by Webpack compiler and the compiler object can be accessed throughout the compilation life cycle;
functionLogonbuildwebpackplugin(){}; Pass a function as a plug-in through Function.prototype.apply, in the configuration so that you can inline the custom plugin Logonbuildwebpackplugin. prototype. Apply=function(Compiler){Compiler.Plugin(' Run ',function (Compiler{console log ( "Hello,let ' s start! "callback (}) } 5.2 Plug-ins can carry parameters/options, and the Plugins
property must be passed into the new
instance in the Webpack configuration, as shown in the following code.
/span>
Const Htmlwebpackplugin=Require(' Html-webpack-plugin '); Const Webpack=Require(' Webpack '); ...Const CONFIG={Entry: ...Output:{ ... }, module{... < Span class= "token string" > }[new webpack .optimize ( ,
//plugin installed via NPM
< Span class= "token punctuation" >< Span class= "token punctuation" > new htmlwebpackplugin{template}
//built-in plug-in
< Span class= "token punctuation" > ]};
Module.exports = Config
Webpack Framework Knowledge Collation--plugins