mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Build: Switch the minifier from UglifyJS to Terser
UglifyJS is ES5-only, while Terser supports newer ECMAScript versions. jQuery is authored in ES5 but jQuery 4.x will also have an ESM build that cannot be minified using UglifyJS directly. We could strip the `export` statement, minify via UglifyJS and re-add one but that increases complexity & may not fully play nice with source maps. On the other hand, switching to Terser increases the minfied size by just 324 bytes and the minified gzipped one by just 70 bytes. Such differences largely disappear among bigger size gains from the `3.x-stable` line - around 2.7 KB minified gzipped as of now. Closes gh-5258
This commit is contained in:
parent
988a56847d
commit
27303c6be0
27
Gruntfile.js
27
Gruntfile.js
@ -333,25 +333,26 @@ module.exports = function( grunt ) {
|
|||||||
files: [ "<%= eslint.dev.src %>" ],
|
files: [ "<%= eslint.dev.src %>" ],
|
||||||
tasks: [ "dev" ]
|
tasks: [ "dev" ]
|
||||||
},
|
},
|
||||||
uglify: {
|
terser: {
|
||||||
all: {
|
all: {
|
||||||
files: {
|
files: {
|
||||||
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
|
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
|
||||||
"dist/<%= grunt.option('filename') %>"
|
"dist/<%= grunt.option('filename') %>"
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
preserveComments: false,
|
ecma: 5,
|
||||||
sourceMap: true,
|
sourceMap: {
|
||||||
sourceMapName:
|
filename: "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>"
|
||||||
"dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
|
},
|
||||||
report: "min",
|
format: {
|
||||||
output: {
|
ascii_only: true,
|
||||||
"ascii_only": true
|
comments: false,
|
||||||
|
preamble: "/*! jQuery v<%= pkg.version %> | " +
|
||||||
|
"(c) OpenJS Foundation and other contributors | " +
|
||||||
|
"jquery.org/license */"
|
||||||
},
|
},
|
||||||
banner: "/*! jQuery v<%= pkg.version %> | " +
|
|
||||||
"(c) OpenJS Foundation and other contributors | jquery.org/license */",
|
|
||||||
compress: {
|
compress: {
|
||||||
"hoist_funs": false,
|
hoist_funs: false,
|
||||||
loops: false
|
loops: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -420,7 +421,7 @@ module.exports = function( grunt ) {
|
|||||||
grunt.registerTask( "dev", [
|
grunt.registerTask( "dev", [
|
||||||
"build:*:*",
|
"build:*:*",
|
||||||
runIfNewNode( "newer:eslint:dev" ),
|
runIfNewNode( "newer:eslint:dev" ),
|
||||||
"newer:uglify",
|
"newer:terser",
|
||||||
"remove_map_comment",
|
"remove_map_comment",
|
||||||
"dist:*",
|
"dist:*",
|
||||||
"qunit_fixture",
|
"qunit_fixture",
|
||||||
@ -431,7 +432,7 @@ module.exports = function( grunt ) {
|
|||||||
runIfNewNode( "eslint:dev" ),
|
runIfNewNode( "eslint:dev" ),
|
||||||
"build:*:*",
|
"build:*:*",
|
||||||
"amd",
|
"amd",
|
||||||
"uglify",
|
"terser",
|
||||||
"remove_map_comment",
|
"remove_map_comment",
|
||||||
"dist:*",
|
"dist:*",
|
||||||
"test:prepare",
|
"test:prepare",
|
||||||
|
@ -339,6 +339,6 @@ module.exports = function( grunt ) {
|
|||||||
"";
|
"";
|
||||||
|
|
||||||
grunt.log.writeln( "Creating custom build...\n" );
|
grunt.log.writeln( "Creating custom build...\n" );
|
||||||
grunt.task.run( [ "build:*:*" + ( modules ? ":" + modules : "" ), "uglify", "dist" ] );
|
grunt.task.run( [ "build:*:*" + ( modules ? ":" + modules : "" ), "terser", "dist" ] );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
var fs = require( "fs" );
|
var fs = require( "fs" );
|
||||||
|
|
||||||
module.exports = function( grunt ) {
|
module.exports = function( grunt ) {
|
||||||
var config = grunt.config( "uglify.all.files" );
|
var config = grunt.config( "terser.all.files" );
|
||||||
grunt.registerTask( "remove_map_comment", function() {
|
grunt.registerTask( "remove_map_comment", function() {
|
||||||
var minLoc = grunt.config.process( Object.keys( config )[ 0 ] );
|
var minLoc = grunt.config.process( Object.keys( config )[ 0 ] );
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
"grunt-babel": "8.0.0",
|
"grunt-babel": "8.0.0",
|
||||||
"grunt-cli": "1.4.3",
|
"grunt-cli": "1.4.3",
|
||||||
"grunt-compare-size": "0.4.2",
|
"grunt-compare-size": "0.4.2",
|
||||||
"grunt-contrib-uglify": "3.4.0",
|
|
||||||
"grunt-contrib-watch": "1.1.0",
|
"grunt-contrib-watch": "1.1.0",
|
||||||
"grunt-eslint": "24.0.0",
|
"grunt-eslint": "24.0.0",
|
||||||
"grunt-git-authors": "3.2.0",
|
"grunt-git-authors": "3.2.0",
|
||||||
@ -43,6 +42,7 @@
|
|||||||
"grunt-karma": "4.0.2",
|
"grunt-karma": "4.0.2",
|
||||||
"grunt-newer": "1.3.0",
|
"grunt-newer": "1.3.0",
|
||||||
"grunt-npmcopy": "0.2.0",
|
"grunt-npmcopy": "0.2.0",
|
||||||
|
"grunt-terser": "2.0.0",
|
||||||
"gzip-js": "0.3.2",
|
"gzip-js": "0.3.2",
|
||||||
"husky": "4.2.5",
|
"husky": "4.2.5",
|
||||||
"jsdom": "19.0.0",
|
"jsdom": "19.0.0",
|
||||||
@ -67,8 +67,8 @@
|
|||||||
"rollup": "2.21.0",
|
"rollup": "2.21.0",
|
||||||
"sinon": "7.3.1",
|
"sinon": "7.3.1",
|
||||||
"strip-json-comments": "3.1.1",
|
"strip-json-comments": "3.1.1",
|
||||||
"testswarm": "1.1.2",
|
"terser": "5.17.6",
|
||||||
"uglify-js": "3.4.7"
|
"testswarm": "1.1.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm install && grunt",
|
"build": "npm install && grunt",
|
||||||
|
Loading…
Reference in New Issue
Block a user