简体   繁体   English

Gulp正在编译每个Js文件

[英]Gulp is compiling every Js-file

i have a problem with my gulp. 我的口渴有问题。
Its works fine and its really fast but Gulp is compiling all js files in my project... 它工作正常,速度非常快,但是Gulp正在编译我项目中的所有js文件...

my gulp-watch: 我的手表

gulp.task('watch', function () {
    gulp.watch(sassFilesWatch, ['styles']);
    gulp.watch(jsFilesWatch, ['uglify'])
});

My array: 我的数组:

var jsFilesWatch = [
    'clients/*/template/lib/jscripts/*.js',
    'clients/*/template/modules/**/*.js',
    'system/lib/jscripts/*.js',
    'system/mod/**/*.js',
    'clients/core/modules/**/*.js',
    '!/**/*.min.js'
];

Thats my function: 那就是我的功能:

gulp.task('uglify', function(){
    pump([
        gulp.src(jsFilesWatch, {
            base: './'
        }),
        debug({
            title: 'Compiled',
            showFiles: false,
        }),
        uglify(),
        rename({ suffix: '.min' }),
        gulp.dest('./')
    ]);
});

And thats the output: 那就是输出:
Output 输出量

Just my saved file should be compiled how can i do that? 只是我保存的文件应该被编译怎么办?

thanks alot 非常感谢

It seems all your files with .js extensions are being debugged, uglified and minified. 您所有带有.js扩展名的文件似乎都在调试,丑化和缩小。 Which saved file are you trying to compile? 您要编译哪个保存的文件?

**/*.js uses the gulp command to watch all files with the .js extension in all folders. ** / *。js使用gulp命令来监视所有文件夹中带有.js扩展名的所有文件。

You could use .pipe() 您可以使用.pipe()

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

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

Have a look into this Plugin, That will solve your problem 看看这个插件,这将解决您的问题

https://www.npmjs.com/package/gulp-changed https://www.npmjs.com/package/gulp-changed

Try Changing your task to, 尝试将任务更改为

gulp.task('uglify', function(){
    pump([
        gulp.src(jsFilesWatch, {
            base: './'
        }),
        changed('dist'),
        ngAnnotate(),
        debug({
            title: 'Compiled',
            showFiles: false,
        }),
        uglify(),
        rename({ suffix: '.min' }),
        gulp.dest('./')
    ]);
});

Note: this might run all your .js files at first time after you run your task, but it will identify the changed file on subsequent runs 注意:这可能会在您运行任务后第一次运行所有.js文件,但是它将在以后的运行中标识更改的文件

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

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