grunt-terser
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -5,21 +5,11 @@ /* | ||
* | ||
* Copyright (c) 2018 Alexandr Dascal | ||
* Copyright (c) 2021 Alexandr Dascal | ||
* Licensed under the MIT license. | ||
*/ | ||
'use strict'; | ||
module.exports = function(grunt) { | ||
module.exports = (grunt) => { | ||
// Project configuration. | ||
grunt.initConfig({ | ||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'tasks/*.js', | ||
'<%= nodeunit.tests %>' | ||
], | ||
options: { | ||
jshintrc: '.jshintrc' | ||
} | ||
eslint: { | ||
all: ['Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>'], | ||
}, | ||
@@ -29,3 +19,3 @@ | ||
clean: { | ||
tests: ['tmp'] | ||
tests: ['tmp'], | ||
}, | ||
@@ -36,17 +26,15 @@ | ||
default_options: { | ||
options: { | ||
files: { | ||
'tmp/default_options': ['test/fixtures/*.js'], | ||
}, | ||
files: { | ||
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123'] | ||
} | ||
}, | ||
custom_options: { | ||
options: { | ||
separator: ': ', | ||
punctuation: ' !!!' | ||
module: true, | ||
sourceMap: true, | ||
}, | ||
files: { | ||
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123'] | ||
} | ||
} | ||
'tmp/custom_options': ['test/fixtures/*.js'], | ||
}, | ||
}, | ||
}, | ||
@@ -56,5 +44,4 @@ | ||
nodeunit: { | ||
tests: ['test/*_test.js'] | ||
} | ||
tests: ['test/*_test.js'], | ||
}, | ||
}); | ||
@@ -66,3 +53,3 @@ | ||
// These plugins provide necessary tasks. | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-eslint'); | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
@@ -75,5 +62,6 @@ grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
grunt.registerTask('lint', ['eslint']); | ||
// By default, lint and run all tests. | ||
grunt.registerTask('default', ['jshint', 'test']); | ||
grunt.registerTask('default', ['lint', 'test']); | ||
}; |
{ | ||
"name": "grunt-terser", | ||
"description": "Grunt plugin for A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/adascal/grunt-terser", | ||
@@ -20,19 +20,24 @@ "author": { | ||
"type": "MIT", | ||
"url": "https://github.com/adascal/grunt-terser/blob/master/LICENSE-MIT" | ||
"url": "https://github.com/adascal/grunt-terser/blob/master/LICENSE" | ||
} | ||
], | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=10.0.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
"test": "grunt test", | ||
"lint": "grunt lint" | ||
}, | ||
"dependencies": { | ||
"terser": "^4.3.9" | ||
"peerDependencies": { | ||
"grunt": "1.x", | ||
"terser": "5.x" | ||
}, | ||
"devDependencies": { | ||
"grunt": "^1.0.4", | ||
"eslint": "^7.2.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"grunt-contrib-clean": "^2.0.0", | ||
"grunt-contrib-jshint": "^2.1.0", | ||
"grunt-contrib-nodeunit": "^2.0.0" | ||
"grunt-contrib-nodeunit": "^2.0.0", | ||
"grunt-eslint": "^23.0.0" | ||
}, | ||
@@ -61,3 +66,6 @@ "keywords": [ | ||
"await" | ||
] | ||
], | ||
"dependencies": { | ||
"grunt": "^1.1.0" | ||
} | ||
} |
@@ -6,4 +6,5 @@ # grunt-terser | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.5` | ||
This plugin requires Grunt `^1.x` | ||
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: | ||
@@ -24,2 +25,3 @@ | ||
### Overview | ||
In your project's Gruntfile, add a section named `terser` to the data object passed into `grunt.initConfig()`. | ||
@@ -45,5 +47,7 @@ | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
## Release History | ||
_(Nothing yet)_ | ||
- 2021-02-27 v2.0.0 Support terser v5 and async code minify |
@@ -5,11 +5,14 @@ /* | ||
* | ||
* Copyright (c) 2018 Alexandr Dascal | ||
* Copyright (c) 2021 Alexandr Dascal | ||
* Licensed under the MIT license. | ||
*/ | ||
'use strict'; | ||
const { minify } = require('terser'); | ||
var Terser = require('terser'); | ||
module.exports = function(grunt) { | ||
module.exports = ( | ||
/** | ||
* @type import("grunt") | ||
*/ | ||
grunt, | ||
) => { | ||
// Please see the Grunt documentation for more information regarding task | ||
@@ -21,63 +24,77 @@ // creation: http://gruntjs.com/creating-tasks | ||
'Grunt plugin for A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.', | ||
function() { | ||
async function terserTask() { | ||
const done = this.async(); | ||
// Merge task-specific and/or target-specific options with these defaults. | ||
var options = this.options(); | ||
var createdFiles = 0; | ||
/** | ||
* @type import("terser").MinifyOptions | ||
*/ | ||
const options = this.options(); | ||
let createdFiles = 0; | ||
// Iterate over all specified file groups. | ||
this.files.forEach(function(f) { | ||
// Concat specified files. | ||
var src = f.src | ||
.filter(function(filepath) { | ||
// Warn on and remove invalid source files (if nonull was set). | ||
if (!grunt.file.exists(filepath)) { | ||
grunt.log.warn('Source file "' + filepath + '" not found.'); | ||
return false; | ||
} else { | ||
await Promise.all( | ||
this.files.map(async (file) => { | ||
// Concat specified files. | ||
const src = file.src | ||
.filter((filepath) => { | ||
// Warn on and remove invalid source files (if nonull was set). | ||
if (!grunt.file.exists(filepath)) { | ||
grunt.log.warn(`Source file "${filepath}" not found.`); | ||
return false; | ||
} | ||
return true; | ||
} | ||
}) | ||
.reduce(function(sources, filepath) { | ||
sources[filepath] = grunt.file.read(filepath); | ||
}) | ||
.reduce( | ||
(sources, filepath) => ({ | ||
...sources, | ||
[filepath]: grunt.file.read(filepath), | ||
}), | ||
{}, | ||
); | ||
return sources; | ||
}, {}); | ||
// Minify file code. | ||
const result = await minify(src, options); | ||
// Minify file code. | ||
var result = Terser.minify(src, options); | ||
if (result.error) { | ||
grunt.log.error(result.error); | ||
return false; | ||
} | ||
if (result.error) { | ||
grunt.log.error(result.error); | ||
return false; | ||
} | ||
if (result.warnings) { | ||
grunt.log.warn(result.warnings.join('\n')); | ||
} | ||
if (result.warnings) { | ||
grunt.log.warn(result.warnings.join('\n')); | ||
} | ||
// Write the destination file. | ||
grunt.file.write(file.dest, result.code); | ||
// Write the destination file. | ||
grunt.file.write(f.dest, result.code); | ||
if (options.sourceMap) { | ||
const mapFileName = options.sourceMap.filename | ||
? options.sourceMap.filename | ||
: `${file.dest}.map`; | ||
// Write the source map file. | ||
grunt.file.write(mapFileName, result.map); | ||
} | ||
if (options.sourceMap) { | ||
var mapFileName = options.sourceMap.filename | ||
? options.sourceMap.filename | ||
: f.dest + '.map'; | ||
// Write the source map file. | ||
grunt.file.write(mapFileName, result.map); | ||
} | ||
// Print a success message for individual files only if grunt is run with --verbose flag | ||
grunt.log.verbose.writeln(`File "${file.dest}" created.`); | ||
// Print a success message for individual files only if grunt is run with --verbose flag | ||
grunt.verbose.writeln('File "' + f.dest + '" created.'); | ||
// Increment created files counter | ||
createdFiles += 1; | ||
}), | ||
); | ||
// Increment created files counter | ||
createdFiles++; | ||
}); | ||
if (createdFiles > 0) { | ||
grunt.log.ok( | ||
`${createdFiles} grunt.util.pluralize(createdFiles, 'file/files') created.` | ||
`${createdFiles} ${grunt.util.pluralize( | ||
createdFiles, | ||
'file/files', | ||
)} created.`, | ||
); | ||
} | ||
} | ||
done(); | ||
}, | ||
); | ||
}; |
@@ -1,5 +0,3 @@ | ||
'use strict'; | ||
const grunt = require('grunt'); | ||
var grunt = require('grunt'); | ||
/* | ||
@@ -26,15 +24,15 @@ ======== A Handy Little Nodeunit Reference ======== | ||
exports.terser = { | ||
setUp: function(done) { | ||
setUp(done) { | ||
// setup here if necessary | ||
done(); | ||
}, | ||
default_options: function(test) { | ||
default_options(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/default_options'); | ||
var expected = grunt.file.read('test/expected/default_options'); | ||
const actual = grunt.file.read('tmp/default_options'); | ||
const expected = grunt.file.read('test/expected/default_options'); | ||
test.equal( | ||
actual, | ||
expected, | ||
'should describe what the default behavior is.' | ||
'should describe what the default behavior is.', | ||
); | ||
@@ -44,11 +42,11 @@ | ||
}, | ||
custom_options: function(test) { | ||
custom_options(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/custom_options'); | ||
var expected = grunt.file.read('test/expected/custom_options'); | ||
const actual = grunt.file.read('tmp/custom_options'); | ||
const expected = grunt.file.read('test/expected/custom_options'); | ||
test.equal( | ||
actual, | ||
expected, | ||
'should describe what the custom option(s) behavior is.' | ||
'should describe what the custom option(s) behavior is.', | ||
); | ||
@@ -55,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10160
184
51
3
7
+ Addedgrunt@^1.1.0
+ Added@jridgewell/gen-mapping@0.3.8(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/source-map@0.3.6(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarray-each@1.0.1(transitive)
+ Addedarray-slice@1.1.0(transitive)
+ Addedasync@3.2.6(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcolors@1.1.2(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddateformat@4.6.3(transitive)
+ Addeddetect-file@1.0.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedeventemitter2@0.4.14(transitive)
+ Addedexit@0.1.2(transitive)
+ Addedexpand-tilde@2.0.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfindup-sync@4.0.05.0.0(transitive)
+ Addedfined@1.2.0(transitive)
+ Addedflagged-respawn@1.0.1(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgetobject@1.0.2(transitive)
+ Addedglob@7.1.7(transitive)
+ Addedglobal-modules@1.0.0(transitive)
+ Addedglobal-prefix@1.0.2(transitive)
+ Addedgrunt@1.6.1(transitive)
+ Addedgrunt-cli@1.4.3(transitive)
+ Addedgrunt-known-options@2.0.0(transitive)
+ Addedgrunt-legacy-log@3.0.0(transitive)
+ Addedgrunt-legacy-log-utils@2.1.0(transitive)
+ Addedgrunt-legacy-util@2.0.1(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhomedir-polyfill@1.0.3(transitive)
+ Addedhooker@0.2.3(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedinterpret@1.1.0(transitive)
+ Addedis-absolute@1.0.0(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-relative@1.0.0(transitive)
+ Addedis-unc-path@1.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedliftup@3.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmake-iterator@1.0.1(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedminimatch@3.0.8(transitive)
+ Addednopt@3.0.64.0.3(transitive)
+ Addedobject.defaults@1.1.0(transitive)
+ Addedobject.map@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedparse-filepath@1.0.2(transitive)
+ Addedparse-passwd@1.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-root@0.1.1(transitive)
+ Addedpath-root-regex@0.1.2(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedrechoir@0.7.1(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedresolve-dir@1.0.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsprintf-js@1.0.31.1.3(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedterser@5.39.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedunc-path-regex@0.1.2(transitive)
+ Addedunderscore.string@3.3.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedv8flags@3.2.0(transitive)
+ Addedwhich@1.3.12.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedterser@^4.3.9
- Removedterser@4.8.1(transitive)