这段将多个js文件合二为一的代码有什么问题?

What is wrong with this code that combines multiple js files to one?(这段将多个js文件合二为一的代码有什么问题?)
本文介绍了这段将多个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:

"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文件合二为一的代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)