1. How to solve the file name after each package to remember the problem of re-use
1.1 First to use a plug-in Webpack: NMP install Html-webpack-plugin--save-dev
1.2 Introducing a reference to the plugin in Webpack-config.js
2. How to output the output file to a different directory
2.1 First Change path path
2.2 Next change the filename path (see webpack.config.js for details)
3. Passing parameters
3.1 First in the Plugins configuration parameters (details see webpack.config.js in the title of the plugins (title is a personal defined variable, if you want to pass multiple parameters can be defined title1 title2, etc.))
3.2 Calling parameters, in HTML tags
<title><%= htmlwebpackplugin.options.title%></title>
4. Traverse the values in the Htmlwebpackplugin object (not for the project, only for learning)
<%for (Var key in Htmlwebpackplugin.files) {%>
<%=key%>: <%=json.stringify (Htmlwebpackplugin.files[key])%>
<%}%>
<%for (Var key in htmlwebpackplugin.options) {%>
<%=key%>: <%=json.stringify (Htmlwebpackplugin.options[key])%>
<%}%>
5. Want to put part of the introduction of the JS file after the package is placed in the head, part of the body. At this time we can only manually write the JS code to change, the configuration is not up to
5.1 First in the head tag of their own index.html, write the following code to put the package JS reference generated by main in the head
<script type= "Text/javascript" src= "<%=htmlWebpackPlugin.files.chunks.main.entry%>" ></script>
5.2 Put a generated package JS application in body inside body
<script type= ' text/javascript ' src= ' <%=htmlWebpackPlugin.files.chunks.a.entry%> ' ></script>
5.3 You need to change the inject in webpack.config.js to false, or it will automatically introduce the file to the head
6. Go online after packing
Publicpath://On-line, the address of the referenced absolute path after the package will become the Publicpath corresponding value
7. Compressing the packaged files
Minify
8. Multi-page application, only need in plugins, continue new can (see Webpack.config.js), if you want to make the HTML reference different files, only need to be configured in the chunks, but at this time you need to delete the 5 JS code
9. If the interface is very many, at this time we go to one by one of the interface to specify the use of JS will be very troublesome, at this time we will use excludechunks it to indicate which JS files are excluded
10. Directly into the interface embedded in the initialization interface, in its own introduction template (index.html) to write the following code (head write, the main.js embedded in the way)
<script type= "Text/javascript" >
<%=COMPILATION.ASSETS[HTMLWEBPACKPLUGIN.FILES.CHUNKS.MAIN.ENTRY.SUBSTR ( HtmlWebpackPlugin.files.publicPath.length)].source ()%>
</script>
11. How external connections to public methods introduce files
<%for (var k in htmlWebpackPlugin.files.chunks) {%>
<%if (k!== ' main ') {%>
<script type= "Text/javascript" src= "<%=htmlWebpackPlugin.files.chunks[k].entry%>" ></script>
<%}%>
<%}%>
Webpack automatically generated HTML