From 302b488b9214e14830496578f7cf0aebcc33c132 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Mon, 3 Mar 2025 18:58:38 +0100 Subject: 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 --- build/tasks/minify.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 build/tasks/minify.js (limited to 'build/tasks') 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(); +} ); + +}; -- cgit v1.2.3