Skip to content
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
11 changes: 4 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ const cssFiles = [

// minified files
const minify = {
options: {
preserveComments: false
},
main: {
options: {
banner: createBanner( uiFiles )
Expand Down Expand Up @@ -174,7 +171,7 @@ grunt.initConfig( {
}
},

uglify: minify,
minify,
htmllint: {
good: {
options: {
Expand Down Expand Up @@ -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" ] );

};
53 changes: 53 additions & 0 deletions build/tasks/minify.js
Original file line number Diff line number Diff line change
@@ -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();
} );

};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading