javascript - Synchronous grunt.js task execution -
i'm trying extract critical css couple of pages penthouse via gruntjs. guess wrong, since debug message gets printed whole page array before of task being executed. results in generating same file same config.
grunt.registertask('critical-css',function() { grunt.log.writeln( 'extracting critical css initial view' ); var pages = grunt.config('cfg.criticalcss.pages'), viewports = grunt.config('cfg.criticalcss.viewports'); (var = pages.length - 1; >= 0; i--) { grunt.log.writeln( 'processing: ' + pages[i].name ); (var = viewports.length - 1; >= 0; a--) { grunt.config.set( 'ph.server', grunt.config('cfg.criticalcss.server') ); grunt.config.set( 'ph.urltoanalyse', pages[i].url ); grunt.config.set( 'ph.infile', pages[i].in ); grunt.config.set( 'ph.outfile', pages[i].out + '-' + viewports[a].name + '.css' ); grunt.config.set( 'ph.width', viewports[a].width ); grunt.config.set( 'ph.height', viewports[a].height ); // run penthouse task custom config grunt.task.run( 'penthouse' ); } } });
try changing var declarations in loop let
you can use let keyword bind variables locally in scope of loops. - https://developer.mozilla.org/en-us/docs/web/javascript/reference/statements/let#let-scoped_variables_in_for_loops
for (let = pages.length - 1; >= 0; i--) { grunt.log.writeln( 'processing: ' + pages[i].name ); (let = viewports.length - 1; >= 0; a--) { grunt.config.set( 'ph.server', grunt.config('cfg.criticalcss.server') ); grunt.config.set( 'ph.urltoanalyse', pages[i].url ); grunt.config.set( 'ph.infile', pages[i].in ); grunt.config.set( 'ph.outfile', pages[i].out + '-' + viewports[a].name + '.css' ); grunt.config.set( 'ph.width', viewports[a].width ); grunt.config.set( 'ph.height', viewports[a].height ); // run penthouse task custom config grunt.task.run( 'penthouse' ); } }
Comments
Post a Comment