If you use JQuery in your projects, then I'm sure you use $(document).ready(function(){}).
This grunt task will help you, wrapping your concatenated .js file into $(document).ready(function(){}).
npm install grunt-jquery-ready --dev-save
grunt.initConfig({
'jquery-ready' : {
path: 'public/scrips.js',
runSync: false
}
grunt.loadNpmTasks('grunt-jquery-ready');
grunt.registerTask('default', "jquery-ready");
});
grunt.initConfig({
'jquery-ready' : {
path: ['public/script_one.js', 'public/script_two.js'],
outputFile: 'public/bundled_ready.js',
runSync: true
}
});
grunt.loadNpmTasks('grunt-jquery-ready');
grunt.registerTask('default', 'jquery-ready');
grunt.initConfig({
'jquery-ready': {
path: {
'public/output_one.js': ['public/script_one.js', 'public/script_two.js'],
'public/output_two.js': ['public/single_file.js']
}
}
});
grunt.loadNpmTasks('grunt-jquery-ready');
grunt.registerTask('default', 'jquery-ready');
- path - specify path to .js file that you want to have .ready() function, might also be an array of filenames
- runSync - If this task should be Run in synchronous way (default: true)
- outputFile - Specify the output file if you use multiple inputs
grunt