如何仅对更改的文件进行grunt-newer run requirejs?

时间:2017-01-06 04:21:21

标签: gruntjs grunt-contrib-watch

我只能找到examples关于在搜索过程中使用grunt-newerjshint而不是requirejs。所以我在我的grunt配置文件中使用这个配置:

watch: {
    options: {
        nospawn: true
    },
    js: {
        files: [
            'public/**/*.js',
            '!public/asset/**/*.js'
        ],
        tasks: ['newer:requirejs']
    },
},
requirejs: getRequirejsOptions(),
...

requirejs选项是这样的:

module.exports = function () {
    var options = {};

    files.forEach(function (file) {
        options[file] = {
            options: {
                baseUrl: path.join(__dirname, '../public'),
                include: file,
                create: true,
                out: path.join(__dirname, '../public/asset/', file + '.js'),
                optimize: process.env.NODE_ENV == 'local' ? 'none' : 'uglify',
                preserveLicenseComments: !false,
                packages: [
                  ...
                ]
            }
        }
    });

    return options;
}

它确实触发grunt watch仅对已更改的文件运行requirejs

$ grunt watch                                                       
Running "watch" task Waiting...
>> File "public/stock/js/main.js" changed.

Running "newer:shell:requirejs" (newer) task No newer files to process.

Running "watch" task Completed in 1.834s at Fri Jan 06 2017 12:08:05 GMT+0800 (CST) - Waiting...

但刷新浏览器后,我发现源文件没有改变。

0 个答案:

没有答案