Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite242187

Browse files
authored
Build: Switch form Terser to SWC for JS minification (#5286)
Also, as part of this, fix the `file` & `sources` properties of the source mapfile.Fixesgh-5285Closesgh-5286Refgh-5258
1 parent198b41c commite242187

File tree

5 files changed

+88
-19
lines changed

5 files changed

+88
-19
lines changed

‎Gruntfile.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,27 +312,41 @@ module.exports = function( grunt ) {
312312
files:["<%= eslint.dev.src %>"],
313313
tasks:["dev"]
314314
},
315-
terser:{
315+
minify:{
316316
all:{
317317
files:{
318318
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
319319
"dist/<%= grunt.option('filename') %>"
320320
},
321321
options:{
322-
ecma:5,
323322
sourceMap:{
324-
filename:"dist/<%= grunt.option('filename').replace('.js', '.min.map') %>"
325-
},
326-
format:{
327-
ascii_only:true,
328-
comments:false,
329-
preamble:"/*! jQuery v<%= pkg.version %> | "+
330-
"(c) OpenJS Foundation and other contributors | "+
331-
"jquery.org/license */"
323+
filename:"dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
324+
325+
// The map's `files` & `sources` property are set incorrectly, fix
326+
// them via overrides from the task config.
327+
// See https://github.com/swc-project/swc/issues/7588#issuecomment-1624345254
328+
overrides:{
329+
file:"jquery.min.js",
330+
sources:[
331+
"jquery.js"
332+
]
333+
}
332334
},
333-
compress:{
334-
hoist_funs:false,
335-
loops:false
335+
swc:{
336+
format:{
337+
ecma:5,
338+
asciiOnly:true,
339+
comments:false,
340+
preamble:"/*! jQuery v4.0.0-pre | "+
341+
"(c) OpenJS Foundation and other contributors | "+
342+
"jquery.org/license */\n"
343+
},
344+
compress:{
345+
ecma:5,
346+
hoist_funs:false,
347+
loops:false
348+
},
349+
mangle:true
336350
}
337351
}
338352
}
@@ -400,7 +414,7 @@ module.exports = function( grunt ) {
400414
grunt.registerTask("dev",[
401415
"build:*:*",
402416
runIfNewNode("newer:eslint:dev"),
403-
"newer:terser",
417+
"newer:minify",
404418
"remove_map_comment",
405419
"dist:*",
406420
"qunit_fixture",
@@ -410,7 +424,7 @@ module.exports = function( grunt ) {
410424
grunt.registerTask("default",[
411425
runIfNewNode("eslint:dev"),
412426
"build:*:*",
413-
"terser",
427+
"minify",
414428
"remove_map_comment",
415429
"dist:*",
416430
"test:prepare",

‎build/tasks/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,6 @@ module.exports = function( grunt ) {
339339
"";
340340

341341
grunt.log.writeln("Creating custom build...\n");
342-
grunt.task.run(["build:*:*"+(modules ?":"+modules :""),"terser","dist"]);
342+
grunt.task.run(["build:*:*"+(modules ?":"+modules :""),"minify","dist"]);
343343
});
344344
};

‎build/tasks/minify.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Minify JavaScript using SWC.
3+
*/
4+
5+
"use strict";
6+
7+
module.exports=(grunt)=>{
8+
constswc=require("@swc/core");
9+
10+
grunt.registerMultiTask(
11+
"minify",
12+
"Minify JavaScript using SWC",
13+
asyncfunction(){
14+
constdone=this.async();
15+
constoptions=this.options();
16+
constsourceMapFilename=options.sourceMap&&options.sourceMap.filename;
17+
constsourceMapOverrides=options.sourceMap&&options.sourceMap.overrides||{};
18+
19+
awaitPromise.all(this.files.map(async({ src, dest})=>{
20+
if(src.length!==1){
21+
grunt.fatal("The minify task requires a single source per destination");
22+
}
23+
24+
const{ code,map:incompleteMap}=awaitswc.minify(
25+
grunt.file.read(src[0]),
26+
{
27+
...options.swc,
28+
inlineSourcesContent:false,
29+
sourceMap:sourceMapFilename ?
30+
{
31+
filename:sourceMapFilename
32+
} :
33+
false
34+
}
35+
);
36+
37+
grunt.file.write(dest,code);
38+
39+
if(sourceMapFilename){
40+
41+
// Apply map overrides if needed. See the task config description
42+
// for more details.
43+
constmapObject={
44+
...JSON.parse(incompleteMap),
45+
...sourceMapOverrides
46+
};
47+
constmap=JSON.stringify(mapObject);
48+
49+
grunt.file.write(sourceMapFilename,map);
50+
}
51+
}));
52+
53+
done();
54+
}
55+
);
56+
};

‎build/tasks/sourcemap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
varfs=require("fs");
44

55
module.exports=function(grunt){
6-
varconfig=grunt.config("terser.all.files");
6+
varconfig=grunt.config("minify.all.files");
77
grunt.registerTask("remove_map_comment",function(){
88
varminLoc=grunt.config.process(Object.keys(config)[0]);
99

‎package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"devDependencies": {
2727
"@babel/core":"7.10.5",
2828
"@babel/plugin-transform-for-of":"7.10.4",
29+
"@swc/core":"1.3.66",
2930
"colors":"1.4.0",
3031
"commitplease":"3.2.0",
3132
"core-js-bundle":"3.6.5",
@@ -42,7 +43,6 @@
4243
"grunt-karma":"4.0.2",
4344
"grunt-newer":"1.3.0",
4445
"grunt-npmcopy":"0.2.0",
45-
"grunt-terser":"2.0.0",
4646
"gzip-js":"0.3.2",
4747
"husky":"4.2.5",
4848
"jsdom":"19.0.0",
@@ -67,7 +67,6 @@
6767
"rollup":"2.21.0",
6868
"sinon":"7.3.1",
6969
"strip-json-comments":"3.1.1",
70-
"terser":"5.17.6",
7170
"testswarm":"1.1.2"
7271
},
7372
"scripts": {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp