Webpack2 use ch4-to index.html file parameters to the root directory and use arguments to compress HTML using the on-line resource

Source: Internet
Author: User

1 webpack.config.js

Const WEBPACK = require (' Webpack '), Htmlwebpackplugin= Require (' Html-webpack-plugin '), Path= Require (' path '); Module.exports={entry: {main:'./src/script/main.js ', A:'./src/script/a.js '}, Output: {path:path.resolve (__dirname,'./dist '), FileName:' Js/[name]-[chunkhash].js ', Publicpath:' http://cdn.com/'//path output When the directory Publicpath understood as a placeholder, need to address the line}, plugins: [NewHtmlwebpackplugin ({//filename: ' index-[hash].html ',FileName: ' index.html ',//avoid generating different names each time. html is generated index.html at this timeTemplate: ' index.html ',            //inject: ' Head ',Injectfalse, Title:' Webpack is good module pack ', Date:NewDate (), minify: {//compress the current HTML fileRemovecomments:true,//Delete a commentCollapsewhitespace:true //Remove Spaces            }        })    ]};

2 root directory index.html

The. html here is the same as the. Ejs template, you can use the JS syntax <%=%> <%%>, let in, loops, etc.

<! DOCTYPE html> htmlwebpackplugin) {%>        <%= key%>    <%}%>    <!--comment Content-    <script type= "Text/javascript" src= "<%= Htmlwebpackplugin.files.chunks.a.entry%> "></script></body>

3 compiling

<! DOCTYPE html>//cdn.com/js/ Main-723f6c1682e09396ec6f.js "></script>

Can see the compression, transfer parameters, the header body is not introduced into JS, (online) are to achieve

Webpack2 use ch4-to index.html file parameters to the root directory and use arguments to compress HTML using the on-line resource

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.