"Nodejs+gulp+webpack Basic Combat" course notes (vii)--Using Gulp automatic Configuration "spit" to Webpack execution

Source: Internet
Author: User

  First, we use Gulp to automate the entry file. We refer to the rules of this course to categorize and organize documents that need to be imported.

First, we have created the SRC folder. Under the src file, create a home folder called modules. A colleague creates several subfolders, and the basic rule is to create a folder name that represents our portal node name.

(this figure is for reference only, folder name and file name can be customized)

  Then we came to Gulpfile.js, wrote a task, and traversed the folders and sub-files in the Modules folder in Gulpfile (for demonstration convenience, we traverse level 2 by default.) The first level must be the folder name, the second level must be a JS file. 

varWebpack_config = require ("./webpack.config.js"); Gp.task ("Config",function(){    varFS = require ("FS"); varRoot = "./src/modules/"; varconfig = {};//Create an empty object        varGet_m = Fs.readdirsync (root);//read the contents of the folder, return an array, here we use synchronous methodGet_m.foreach (function(m) {//Loop through the folder, M is the folder name, also represents the entry node names            varGet_m_file = Fs.readdirsync (root+m); varGetret = Get_m_file.map (function(jsfile) {returnroot+m+ "/" +Jsfile; }) Config[m]=Getret; }) Webpack_config.entry=config; //console.log (config);})//Final BuildGp.task ("Run", [' Config '],function() {Webpack (Webpack_config,function(err,status) {//We need some gulp process here .    })    /*gp.src (['./src/tpl/!*.html ']). Pipe (Gp.dest ('./build/html '))*/})

Above, we re-wrote the Config method inside the gulpfile.js. Implement Gulp Auto-complete configuration and run Webpack packaging.

Copyright NOTICE: NOTE-taker fugitive pawns love freedom, advocating sharing. But this note stems from www.jtthink.com (programmer in the awkward way) Judging teacher's "front- end development of the rapid study of wealth (nodejs+gulp+webpack Basic Combat)". This study note pawn in the blog Park debut, if need to reprint please respect the teacher Labor, retain judging teacher attribution and course source address.

Previous lesson: "Nodejs+gulp+webpack Basic Combat" course notes (vi)--Additional lessons

"Nodejs+gulp+webpack Basic Combat" course notes (vii)--Using Gulp automatic Configuration "spit" to Webpack execution

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.