Use gulp-concat merge js file

1. Install nodejs, build directory, initialize the project

Project to build a gulp


2. Install the plug-gulp-concat

Open a command prompt tool in the project directory

按下 ctrl+r -->  输入 cmd

Installation gulp-concat

npm install gulp-concat --save-dev

It may be slow, wait for some time.

carry out

finish installation


3. How to use

  1. First introduced gulp gulp-concat plug-ins and in the middle of gulpfile.js file in the root directory of the project

Write pictures described here

  1. Define a gulp task

Write pictures described here

//定义一个任务名称 concat 
gulp.task('concat',function(){

    // 找到src目录下的所有文件夹中的所有js文件
    return gulp.src('src/**/*.js')

    //执行concat插件方法,合并的js文件,文件名称为 router.js
        .pipe(concat('router.js'))

    //最后输出到dist/js文件目录下面
        .pipe(gulp.dest('dist/js'));

});

4. merger

Write pictures described here

Published 25 original articles · won praise 31 · views 110 000 +

Guess you like

Origin blog.csdn.net/qq_33236453/article/details/52274875