Skip to content

Commit

Permalink
Adapt grunt-terser task for async minification
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Aug 16, 2020
1 parent ab49099 commit fa59307
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tools/build/grunt-terser.js
@@ -1,8 +1,9 @@
/*
* grunt-terser
* https://github.com/adascal/grunt-terser
* + modifications for async usage with terser v5
*
* Copyright (c) 2018 Alexandr Dascal
* Copyright (c) 2018 Alexandr Dascal, (c) 2020 James Nylen
* Licensed under the MIT license.
*/

Expand All @@ -17,13 +18,15 @@ module.exports = function(grunt) {
grunt.registerMultiTask(
'terser',
'Grunt plugin for A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.',
function() {
async function() {
var done = this.async();

// Merge task-specific and/or target-specific options with these defaults.
var options = this.options();
var createdFiles = 0;

// Iterate over all specified file groups.
this.files.forEach(function(f) {
for (const f of this.files) {
// Concat specified files.
var src = f.src
.filter(function(filepath) {
Expand All @@ -42,7 +45,7 @@ module.exports = function(grunt) {
}, {});

// Minify file code.
var result = Terser.minify(src, options);
var result = await Terser.minify(src, options);

if (result.error) {
grunt.log.error(result.error);
Expand All @@ -69,13 +72,15 @@ module.exports = function(grunt) {

// Increment created files counter
createdFiles++;
});
}

if (createdFiles > 0) {
grunt.log.ok(
`${createdFiles} ${grunt.util.pluralize(createdFiles, 'file/files')} created.`
);
}

done();
}
);
};

0 comments on commit fa59307

Please sign in to comment.