"Nodejs+gulp+webpack Basic Combat" course notes (eight)--templating development Walkthrough: Detaching a Common header file

Source: Internet
Author: User

Let's start by installing the plugins you need for this lesson:

NPM install raw-loader--save-dev// Example: var header = require ("xxx.html"), the HTML content will be read out

  This is a webpack loader that can return a file as if it were a string.

Here are two ways to use the loader:

1. Write in our webpack config file

{test:/\.html$/,loader: "Loader name"}// This means that all HTML suffixes will use this loader to handle

2. Call the loader when require

Require ("Loader name!xxx.html");

Here, we will also use three ways to load a common header file:

The first type: direct require (XXX) in Login.js, and then insert it using jquery.

// var GetHeader = require ("raw!. /.. /.. /tpl/header.include "); // $ ("#header"). Append (GetHeader);

The second type: Write the <%=require ("raw!xxx.html")%> directly on the page.

<%=require ("raw!. /header.include ")%>.

Third: Using Nodejs code <%=htmlWebPackPlugin.options.xxx%>

New Htmlwebpackplugin ({

Here's a random variable name: Read the file here with the FS module.

})

include:{           header:require (' FS '). Readfilesync ("./src/tpl/head.include")          }
<%=htmlWebpackPlugin.options.include.header%>

"Nodejs+gulp+webpack Basic Combat" course notes (eight)--templating development Walkthrough: Detaching a Common header file

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.