Skip to content

Build: Switch from UglifyJS to SWC minify, make the minified file ES5 #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: monthly

# Group all dependabot version update PRs into one
groups:
github-actions:
applies-to: version-updates
patterns:
- "*"
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ jobs:
NODE_VERSION: [18.x, 20.x, 22.x]
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install xsltproc
- name: Install xsltproc & ImageMagick
run: |
sudo apt-get install xsltproc
sudo apt-get install xsltproc imagemagick

- name: Use Node.js ${{ matrix.NODE_VERSION }}
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: ${{ matrix.NODE_VERSION }}

- name: Cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-npm-lock-${{ hashFiles('**/package-lock.json') }}
Expand Down
11 changes: 5 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ grunt.loadNpmTasks( "grunt-check-modules" );
grunt.loadNpmTasks( "grunt-contrib-clean" );
grunt.loadNpmTasks( "grunt-contrib-copy" );
grunt.loadNpmTasks( "grunt-contrib-handlebars" );
grunt.loadNpmTasks( "grunt-contrib-uglify" );
grunt.loadNpmTasks( "grunt-eslint" );

grunt.initConfig( {
Expand Down Expand Up @@ -61,10 +60,7 @@ grunt.initConfig( {
dest: "app/dist"
}
},
uglify: {
options: {
preserveComments: "some"
},
minify: {

// DownloadBuilder minified frontend bundle
download: {
Expand All @@ -87,6 +83,9 @@ grunt.initConfig( {
}
} );

// local tasks
grunt.loadTasks( "grunt-tasks" );

function log( callback, successMsg, errorMsg ) {
return function( error, result, code ) {
if ( error && errorMsg ) {
Expand Down Expand Up @@ -279,7 +278,7 @@ function buildPackages( folder, callback ) {

grunt.registerTask( "default", [ "check-modules", "eslint", "test" ] );

grunt.registerTask( "build-app", [ "clean", "handlebars", "copy", "uglify" ] );
grunt.registerTask( "build-app", [ "clean", "handlebars", "copy", "minify" ] );

grunt.registerTask( "build-packages", "Builds zip package of each jQuery UI release specified in config file with all components and lightness theme, inside the given folder", function( folder ) {
var done = this.async();
Expand Down
26 changes: 26 additions & 0 deletions grunt-tasks/minify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

const swc = require( "@swc/core" );
const swcOptions = require( "../lib/swc-options" );

module.exports = function( grunt ) {

grunt.registerMultiTask( "minify", async function() {
const done = this.async();

for ( const file of this.files ) {
const contents = file.src
.map( singleFile => grunt.file.read( singleFile ) )
.join( "\n" );

const { code } = await swc.minify( contents, swcOptions );

grunt.file.write( file.dest, code );

grunt.log.writeln( `File ${ file.dest } created.` );
}

done();
} );

};
8 changes: 6 additions & 2 deletions lib/jquery-ui-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var stripBanner, glob, noDirectory,
fs = require( "node:fs" ),
path = require( "node:path" ),
sqwish = require( "sqwish" ),
UglifyJS = require( "uglify-js" ),
swc = require( "@swc/core" ),
swcOptions = require( "./swc-options" ),
util = require( "./util" ),
Files = require( "./files" ),
filesCache = {};
Expand Down Expand Up @@ -91,7 +92,10 @@ JqueryUiFiles.prototype = {
path: file.path.replace( /\.([^.]*)$/, ".min.$1" )
};
if ( ( /\.js$/i ).test( file.path ) ) {
minified[ file.path ].data = UglifyJS.minify( file.data.toString( "utf8" ) ).code;
minified[ file.path ].data = swc.minifySync(
file.data.toString( "utf8" ),
swcOptions
).code;
} else if ( ( /\.css$/i ).test( file.path ) ) {
minified[ file.path ].data = sqwish.minify( file.data.toString( "utf8" ) );
}
Expand Down
10 changes: 3 additions & 7 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var indexTemplate,
sqwish = require( "sqwish" ),
ThemeRoller = require( "./themeroller" ),
semver = require( "semver" ),
UglifyJS = require( "uglify-js" );
swc = require( "@swc/core" ),
swcOptions = require( "./swc-options" );

indexTemplate = handlebars.compile( fs.readFileSync( __dirname + "/../template/zip/index.html", "utf8" ) );

Expand Down Expand Up @@ -340,13 +341,8 @@ extend( Package.prototype, {
}

this.jsBundle.promise.then( function( js ) {
var minJs;
var _banner = banner( pkgJson, jsFileNames, { minify: true } );
var uglifyResult = UglifyJS.minify( js );
if ( uglifyResult.error ) {
throw uglifyResult.error;
}
minJs = uglifyResult.code;
var minJs = swc.minifySync( js, swcOptions ).code;
callback( null, _banner + minJs );
} ).catch( callback );
},
Expand Down
21 changes: 21 additions & 0 deletions lib/swc-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";

module.exports = {
compress: {
ecma: 5,
hoist_funs: false,
loops: false
},
format: {
ecma: 5,
asciiOnly: true,

// That only preserves license comments.
// See https://swc.rs/docs/configuration/minification#note-about-comments
comments: true
},
inlineSourcesContent: false,
mangle: true,
module: false,
sourceMap: false
};
Loading