简体   繁体   English

基本的Gulp Uglify设置?

[英]Basic Gulp Uglify Setup?

I want to take all .js files in my project, and for each, save a minified version in the same directory. 我想将项目中的所有.js文件都保存下来,然后将每个缩小的版本保存在同一目录中。

That is, given this project directory structure: 也就是说,鉴于此项目目录结构:

project/
    gulpfile.js
    basic.js
    Project/
        Project.js
        Toolbelt.js
        Colors/
            RGBA.js
            HSLA.js

My gulpfile should create these minified files: 我的gulpfile应该创建这些缩小的文件:

project/
    basic.js
    basic.min.js // ADDED BY GULP
    Project/
        Project.js
        Project.min.js // ADDED BY GULP
        Toolbelt.js
        Toolbelt.min.js // ADDED BY GULP
        Colors/
            RGBA.js
            RGBA.min.js // ADDED BY GULP
            HSLA.js
            HSLA.min.js // ADDED BY GULP

These seems like it should be relatively straightforward, but I seem to have missed it. 这些似乎应该相对简单一些,但是我似乎错过了。 I'm not sure what I'm doing wrong, but it only seems to work on basic.js ( basic.min.js is created successfully), but it's not working for any files within folders. 我不确定自己在做什么错,但它似乎只能在basic.jsbasic.jsbasic.min.js已成功创建),但不适用于文件夹中的任何文件。 I'm not sure if **.js isn't working as I'm expecting, or gulp.dest('') isn't pointing to the current file's directory.. I've done some experimenting off this, and I'm stumped. 我不确定**.js是否按预期运行,或者gulp.dest('')是否未指向当前文件的目录。我已经对此做了一些试验,我很沮丧。

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

gulp.task('js-minify', function(){
    return gulp.src(['**.js', '!gulpfile.js', '!**.min.js'])
        .pipe(uglify())
        .pipe(rename(function(path){
            path.extname = '.min.js';
         }))
        .pipe(gulp.dest(''));
});

Running gulp js-minify from the command line does not yield the results I'm looking for. 从命令行运行gulp js-minify不会产生我想要的结果。

What am I doing wrong? 我究竟做错了什么?

您的问题是您的gulp.src路径,您没有在目录中查找:

['**/*.js', '!gulpfile.js', '!**/*.min.js'] 

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

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