简体   繁体   English

Gulp-uglify不产生缩小的输出文件

[英]Gulp-uglify not producing minified output file

I've been trying to minify my js files, but I can't get gulp to produce an output file. 我一直在尝试缩小我的js文件,但是我无法使gulp产生输出文件。 To keep things simple, I created a test.js file in my root directory, and I'm trying to get gulp to compress and send a minified file to my public folder. 为了简单起见,我在根目录中创建了一个test.js文件,并且尝试使gulp压缩并将缩小的文件发送到我的公用文件夹。 I've been banging my head on this one for a while, so thanks in advance! 我已经在这上面敲了一段时间,所以在此先感谢! Here's my app.js file 这是我的app.js文件

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var pump = require('pump');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'app_server', 'views'));
app.set('view engine', 'jade');

gulp.task('compress', function(cb) {
  pump([
      gulp.src('./test.js'),
      uglify(),
      gulp.dest('./public')
    ],
    cb
  );
}); 

My test.js file 我的test.js文件

var myFunc = function(aa, bb) {
    return aa + bb;
};

myFunc(1, 2);

And my dependencies 而我的依赖

  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-uglify": "^3.0.0",
    "pump": "^1.0.2"
  }

I figured it out, I just had to install gulp globally, create a gulpFile.js in my root directory, and insert this content in the file: 我知道了,我只需要全局安装gulp,在我的根目录中创建gulpFile.js,然后将以下内容插入文件中:

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
var pump = require('pump');

gulp.task('stream', function() {
    return watch('app_client/**/*.js', function() {
        pump([
            gulp.src([
                'app_client/app.js',
                'app_client/home/home.controller.js'
            ]),
              concat('loc8r.min.js'),
              uglify(),
              gulp.dest('./public/angular')
            ]
        );
    });
}); 

Then in the root directory, head over to the command line and run 然后在根目录中,转到命令行并运行

gulp stream

This method deals with all error handling and automates the process so you don't have to use the CLI every time you update a js file 此方法处理所有错误处理并自动执行该过程,因此您不必在每次更新js文件时都使用CLI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM