Webpack Getting Started tutorial Xi.

Source: Internet
Author: User

60.htmlwebpackplugin plug-in configuration-title use, modify the Webpack.config.js file, modify the contents as follows
var webpack = require (' Webpack '), var htmlwebpackplugin = require (' Html-webpack-plugin '); module.exports = {entry: __ DirName + "/app/greeter.js", Output: {path: __dirname + "/build", FileName: "Bundle.js"},devserver:{contentbase: "./ Public ", Historyapifallback:true,inline:true},module:{loaders:[{test:/\.json$/,loader:" Json-loader "},{test:/\. Js$/,exclude:/node_modules/,loader: ' Babel-loader '},{test:/\.css$/,loader: ' Style-loader!css-loader?modules '}], Plugins:[new Webpack. Bannerplugin ("Copyright Suyan"), new Htmlwebpackplugin ({template:__dirname + "/app/index.tmpl.html", Title: ' Htmlwebpackplugin title Test '}]}
Description
Template: Represents the title of the generated HTML document, configures the item, does not replace the contents of the title element in the specified template file, and uses the template engine syntax in the HTML template file to obtain the configuration item value.
61. Create the template file index.tmpl.html, the template content is as follows
<! DOCTYPE html>
62. Packaging using the Webpack command in a command-line program

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/8D/C1/wKiom1iqSqnzJ-yJAABWSvM61Ec462.png-wh_500x0-wm_ 3-wmp_4-s_1655530827.png "title=" 62.png "alt=" Wkiom1iqsqnzj-yjaabwsvm61ec462.png-wh_50 "/>

63. Look at the directory structure under the build directory, generate a file called index.html, the project directory structure is as follows, the index.html file contents are as follows:

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/8D/C1/wKiom1iqSx_B0Zc0AAAj0rGwRGI888.png-wh_500x0-wm_ 3-wmp_4-s_2450212701.png "title=" 63-1.png "alt=" Wkiom1iqsx_b0zc0aaaj0rgwrgi888.png-wh_50 "/>

<! DOCTYPE html>
Description
Index.html file is generated through our template file index.tmpl.html, in our Webpack.config.js file, we used the Htmlwebpackplugin plugin, in the plug-in configuration item we configured the title: ' Htmlwebpackplugin title test ', and then look at the <title> of our generated index.html file the contents of this tag are exactly what we configured in Webpack.config.js. In the template file we used the <%=htmlwebpackplugin.options.title%> to get the title value in the configuration file.


This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1899356

Webpack Getting Started tutorial Xi.

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.