aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2025-03-03 18:58:38 +0100
committerGitHub <noreply@github.com>2025-03-03 18:58:38 +0100
commit302b488b9214e14830496578f7cf0aebcc33c132 (patch)
treeaa78b29148b71cb70e00287f91a045ca12cf0475
parentfd7dbcdff6b4cec9efadfa4a3e290c397afa3a02 (diff)
downloadjquery-ui-302b488b9214e14830496578f7cf0aebcc33c132.tar.gz
jquery-ui-302b488b9214e14830496578f7cf0aebcc33c132.zip
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. Closes gh-2335 Ref mishoo/UglifyJS#5967 Ref jquery/download.jqueryui.com#629
-rw-r--r--Gruntfile.js11
-rw-r--r--build/tasks/minify.js53
-rw-r--r--package.json2
3 files changed, 58 insertions, 8 deletions
diff --git a/Gruntfile.js b/Gruntfile.js
index 334e4bb1a..cc532b6e9 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -51,9 +51,6 @@ const cssFiles = [
// minified files
const minify = {
- options: {
- preserveComments: false
- },
main: {
options: {
banner: createBanner( uiFiles )
@@ -174,7 +171,7 @@ grunt.initConfig( {
}
},
- uglify: minify,
+ minify,
htmllint: {
good: {
options: {
@@ -403,9 +400,9 @@ grunt.registerTask( "lint", [
"csslint",
"htmllint"
] );
-grunt.registerTask( "build", [ "requirejs", "concat" ] );
+grunt.registerTask( "build", [ "requirejs", "concat", "minify:main" ] );
grunt.registerTask( "default", [ "lint", "build" ] );
-grunt.registerTask( "sizer", [ "requirejs:js", "uglify:main", "compare_size:all" ] );
-grunt.registerTask( "sizer_all", [ "requirejs:js", "uglify", "compare_size" ] );
+grunt.registerTask( "sizer", [ "requirejs:js", "minify:main", "compare_size:all" ] );
+grunt.registerTask( "sizer_all", [ "requirejs:js", "minify", "compare_size" ] );
};
diff --git a/build/tasks/minify.js b/build/tasks/minify.js
new file mode 100644
index 000000000..6d83831ee
--- /dev/null
+++ b/build/tasks/minify.js
@@ -0,0 +1,53 @@
+"use strict";
+
+const swc = require( "@swc/core" );
+
+module.exports = function( grunt ) {
+
+grunt.registerMultiTask( "minify", async function() {
+ const done = this.async();
+ const options = this.options();
+
+ for ( const file of this.files ) {
+ if ( file.src.length === 0 ) {
+ grunt.log.writeln(
+ `No source file found, skipping minification to "${ file.dest }".` );
+ continue;
+ }
+ if ( file.src.length !== 1 ) {
+ grunt.fail.warn( "Minifying multiple source files into one " +
+ "destination file not supported" );
+ }
+
+ const contents = grunt.file.read( file.src[ 0 ] );
+
+ const { code } = await swc.minify(
+ contents,
+ {
+ compress: {
+ ecma: 5,
+ hoist_funs: false,
+ loops: false
+ },
+ format: {
+ ecma: 5,
+ asciiOnly: true,
+ comments: false,
+ preamble: options.banner
+ },
+ inlineSourcesContent: false,
+ mangle: true,
+ module: false,
+ sourceMap: false
+ }
+ );
+
+ grunt.file.write( file.dest, code );
+
+ grunt.log.writeln( `File ${ file.dest } created.` );
+ }
+
+ done();
+} );
+
+};
diff --git a/package.json b/package.json
index 5e8b700ff..c34bef799 100644
--- a/package.json
+++ b/package.json
@@ -55,6 +55,7 @@
"jquery": ">=1.12.0 <5.0.0"
},
"devDependencies": {
+ "@swc/core": "1.11.5",
"commitplease": "3.2.0",
"eslint-config-jquery": "3.0.2",
"grunt": "1.6.1",
@@ -63,7 +64,6 @@
"grunt-contrib-concat": "2.1.0",
"grunt-contrib-csslint": "2.0.0",
"grunt-contrib-requirejs": "1.0.0",
- "grunt-contrib-uglify": "5.2.2",
"grunt-eslint": "24.0.1",
"grunt-git-authors": "3.2.0",
"grunt-html": "17.1.0",