[Webpage] HtmlWebpackPlugin common plug-ins of webpack

 

HtmlWebpackPlugin webpack of common plug-ins

 


1.HtmlWebpackPlugin

Use HtmlWebpackPlugin two functions:
one is the introduction of external resource files such as html script, link dynamically added after each hash the compile, issue prevent external reference file cache
2 entry may be generated to create html files, such as a single-page can be generated html file entry, the configuration of the N html-webpack-plugin may generate N pages inlet

2. Plug principle

The relevant entry in `entry` thunk webpack configuration and` extract-text-webpack-plugin` extracted css style provided by the plug inserted into the `template` or` templateContent` setting specifies an html file generated based on the content, DETAILED insert mode is inserted into the pattern `link`` head` element, `script` inserted in` head` or `body`.

3. The plug-in uses

varHtmlWebpackPlugin=require('html-webpack-plugin')
webpackconfig={
    ...
    plugins:[newHtmlWebpackPlugin( { } )]
}

4. Configuration Parameter Description

title:   generate html document title
filename:  the name of the output file
template: location of the local template
inject:
inject all static resources to the template or templateContent, different configuration values implanted without the same location.

1, true or body: all JavaScript resources inserted into the bottom of the body element
2, head: all JavaScript resources inserted into the head element
3, false: all static resources css and JavaScript will not be injected into the template file

favicon: add specific favicon path to the html document output, this same title configuration items need to dynamically obtain its path value in the template
hash: 
to true | whether false generate a unique hash value for static resources
chuck:   allows you to insert into the template some chunk, do not configure this entry will default all the thunk injected into the template. When a plurality of pages, each page should thunk injected is not the same, the need to inject different for different pages by the thunk configuration;
excludeChunks:  This configuration item and chunks contrary, is not allowed to configure the injection thunk.

Guess you like

Origin www.cnblogs.com/yuanjili666/p/11762227.html