首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >每当杯表检测到文件更改时,打印新消息。

每当杯表检测到文件更改时,打印新消息。
EN

Stack Overflow用户
提问于 2016-12-04 04:18:05
回答 2查看 196关注 0票数 1

每当任何一个js文件被更改时,我都会使用google闭包编译器和一站式监视来编译js文件。

这是密码;

代码语言:javascript
复制
var closureCompiler = require('google-closure-compiler').gulp();
var flatmap = require('gulp-flatmap');    
var watch = require('gulp-watch');

gulp.task('js-closure', function () {
    return watch(['app/js/*.js', 'dist/single.js'], function()
    {
        gulp.src(['app/js/*.js', 'dist/single.js'], {base: './'})
            .pipe(flatmap(function(stream, file) {
                return stream.pipe(closureCompiler({
                    compilation_level: 'SIMPLE_OPTIMIZATIONS',
                    warning_level: 'QUIET',
                    language_in: 'ECMASCRIPT6_STRICT',
                    language_out: 'ECMASCRIPT5_STRICT',
                    output_wrapper: '(function(){\n%output%\n}).call(this)',
                    js_output_file: path.basename(file.path).replace(/js$/, 'min.js')
                }))
            }))
            .pipe(gulp.dest('./dist/js'));
    });
});

效果很好。但是,当检测到js文件已更改并重新编译时,我想将新消息打印到终端。新的信息应该提供这样的信息;

1201hrs - file XXX was changed and recompiled

任何形式的伐木都会受到欢迎。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-12-04 11:34:46

使用口口换位,它只通过已更改的源文件。吞咽记录器是一个基本的流记录器。

代码语言:javascript
复制
var gulp = require("gulp"),
    changedInPlace = require("gulp-changed-in-place"),
    logger = require("gulp-logger");

gulp.task("default", function () {
  return gulp.src("app/js/**/*.js")
    .pipe(changedInPlace())
    // the pipe now contains the files
    // that have changed since the last run
    .pipe(logger({
      before: "Closure compiler task",
      after: "Compiling complete!",
      showChange: true
    }))
    // your own gulp task goes here


    // then pipe to the destination
    .pipe(gulp.dest("./dist/js"));
});
票数 2
EN

Stack Overflow用户

发布于 2016-12-04 12:11:31

下面是问题中提供的源代码所需的修改。这归功于Dan,他提供了使用gulp-changed-in-placegulp-logger的提示。

代码语言:javascript
复制
var closureCompiler = require('google-closure-compiler').gulp();
var flatmap = require('gulp-flatmap');
var watch = require('gulp-watch');
var changedInPlace = require("gulp-changed-in-place");
var logger = require("gulp-logger");

gulp.task('js-closure', function () {
    return watch(['app/js/*.js', 'dist/single.js'], function()
    {
        gulp.src(['app/js/*.js', 'dist/single.js'], {base: './'})
            .pipe(changedInPlace())
            .pipe(flatmap(function(stream, file) {
                return stream.pipe(closureCompiler({
                    compilation_level: 'SIMPLE_OPTIMIZATIONS',
                    warning_level: 'QUIET',
                    language_in: 'ECMASCRIPT6_STRICT',
                    language_out: 'ECMASCRIPT5_STRICT',
                    output_wrapper: '(function(){\n%output%\n}).call(this)',
                    js_output_file: path.basename(file.path).replace(/js$/, 'min.js')
                }))
            }))
            .pipe(logger({
                before: "file was changed",
                after: "file has been recompiled",
                showChange: true
            }))
            .pipe(gulp.dest('./dist/js'));
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40955341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档