How to make grunt-newer run requirejs on only changed files?

325 views Asked by At

I can only find examples about using grunt-newer with jshint but not requirejs during searching. So I use this config in my grunt config file:

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

the requirejs options is like this:

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;
}

it did fire the grunt watch to run requirejs on only changed files:

$ 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...

but after refreshing browser, I found the source file not changed.

0

There are 0 answers