Skip to content

Commit cf832c7

Browse files
committed
Build: Switch from UglifyJS to SWC minify, make the minified file ES5
More recent UglifyJS versions have started converting regular functions to arrow ones, making ES5 source file migrated to a ES2015+ minified one. We want to avoid that even in 1.14.x as long as we keep the source file in ES5. Ref mishoo/UglifyJS#5967 Ref jquery/download.jqueryui.com#629
1 parent fd7dbcd commit cf832c7

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

Gruntfile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ grunt.initConfig( {
174174
}
175175
},
176176

177-
uglify: minify,
177+
minify,
178178
htmllint: {
179179
good: {
180180
options: {
@@ -403,9 +403,9 @@ grunt.registerTask( "lint", [
403403
"csslint",
404404
"htmllint"
405405
] );
406-
grunt.registerTask( "build", [ "requirejs", "concat" ] );
406+
grunt.registerTask( "build", [ "requirejs", "concat", "minify:main" ] );
407407
grunt.registerTask( "default", [ "lint", "build" ] );
408-
grunt.registerTask( "sizer", [ "requirejs:js", "uglify:main", "compare_size:all" ] );
409-
grunt.registerTask( "sizer_all", [ "requirejs:js", "uglify", "compare_size" ] );
408+
grunt.registerTask( "sizer", [ "requirejs:js", "minify:main", "compare_size:all" ] );
409+
grunt.registerTask( "sizer_all", [ "requirejs:js", "minify", "compare_size" ] );
410410

411411
};

build/tasks/minify.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use strict";
2+
3+
const swc = require( "@swc/core" );
4+
5+
module.exports = function( grunt ) {
6+
7+
grunt.registerMultiTask( "minify", async function() {
8+
const done = this.async();
9+
const options = this.options();
10+
11+
for ( const file of this.files ) {
12+
if ( file.src.length !== 1 ) {
13+
grunt.fail.warn( "Minifying multiple source files into one " +
14+
"destination file not supported" );
15+
}
16+
17+
const contents = grunt.file.read( file.src[ 0 ] );
18+
19+
const { code } = await swc.minify(
20+
contents,
21+
{
22+
compress: {
23+
ecma: 5,
24+
hoist_funs: false,
25+
loops: false
26+
},
27+
format: {
28+
ecma: 5,
29+
asciiOnly: true,
30+
comments: false,
31+
preamble: options.banner
32+
},
33+
inlineSourcesContent: false,
34+
mangle: true,
35+
module: false,
36+
sourceMap: false
37+
}
38+
);
39+
40+
grunt.file.write( file.dest, code );
41+
42+
grunt.log.writeln( `File ${ file.dest } created.` );
43+
}
44+
45+
done();
46+
} );
47+
48+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"jquery": ">=1.12.0 <5.0.0"
5656
},
5757
"devDependencies": {
58+
"@swc/core": "1.11.5",
5859
"commitplease": "3.2.0",
5960
"eslint-config-jquery": "3.0.2",
6061
"grunt": "1.6.1",
@@ -63,7 +64,6 @@
6364
"grunt-contrib-concat": "2.1.0",
6465
"grunt-contrib-csslint": "2.0.0",
6566
"grunt-contrib-requirejs": "1.0.0",
66-
"grunt-contrib-uglify": "5.2.2",
6767
"grunt-eslint": "24.0.1",
6868
"grunt-git-authors": "3.2.0",
6969
"grunt-html": "17.1.0",

0 commit comments

Comments
 (0)