此代码将多个js文件合并到一个代码有什么问题? [英] What is wrong with this code that combines multiple js files to one?

查看:285
本文介绍了此代码将多个js文件合并到一个代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个node.js代码,它试图将多个js文件缩小并合并到一个js文件中。

I have this node.js code that tries to minify and combine multiple js files to a single js file.

var concat = require('gulp-concat');
var gulp = require('gulp');

gulp.task('scripts', function() {
    //gulp.src(['./lib/file3.js', './lib/file1.js', './lib/file2.js'])
    gulp.src(['./js/*.js'])
        .pipe(concat('all.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist/'))
});

我所有的js文件都位于js文件夹中。我的node.js文件位于js文件夹之上。我期待单个缩小文件出现在dist文件夹中。当我运行代码时,我什么都看不到,也没有得到任何错误消息。什么可能出错?

All my js files are located in js folder. My node.js file is above the js folder. I am expecting the single minified file to appear in dist folder. I see nothing and get no error message when I run the code. What could have gone wrong?

推荐答案

Gulpfile.js:



Gulpfile.js:

"use strict";

var concat = require('gulp-concat');
var gulp = require('gulp');
var uglify = require('gulp-uglify'); // Add gulp-uglify module to your script

gulp.task('scripts', function() {
    gulp.src('./js/*.js')
        .pipe(concat('all.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist/'));
});



检查package.json依赖关系



运行 npm install 验证所有依赖关系是否正确加载。我认为这是你的问题:

Check package.json dependencies

Run npm install to verify that all dependencies correctly loaded. I think this was your issue:

{
    "dependencies": {
        "gulp-concat": "2.x",
        "gulp": "3.x",
        "gulp-uglify": "1.x"
    }
}

这篇关于此代码将多个js文件合并到一个代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆