-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add swc env minimize benchmark
- Loading branch information
Burhanuddin Udaipurwala
committed
Jun 21, 2023
1 parent
35e8fba
commit e54330e
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { writeFile, unlink } from "fs/promises"; | ||
|
||
export const packageJson = (json) => { | ||
json.browserslist = "> 0.25%, not dead"; | ||
Object.assign(json.devDependencies, { | ||
"@swc/core": "*", | ||
browserslist: "*", | ||
"swc-loader": "*", | ||
"regenerator-runtime": "*", | ||
"terser-webpack-plugin": "*", | ||
}); | ||
return json; | ||
}; | ||
|
||
export const setup = async () => { | ||
await writeFile( | ||
".swcrc", | ||
JSON.stringify( | ||
{ | ||
jsc: { | ||
parser: { | ||
syntax: "ecmascript", | ||
dynamicImport: true, | ||
}, | ||
}, | ||
env: {}, | ||
}, | ||
null, | ||
2 | ||
) | ||
); | ||
}; | ||
|
||
export const teardown = async () => { | ||
try { | ||
await unlink(".swcrc"); | ||
} catch (e) {} | ||
}; | ||
|
||
export const config = (content) => `${content} | ||
var TerserPlugin = require("terser-webpack-plugin"); | ||
module.exports.module = module.exports.module || {}; | ||
module.exports.module.rules = module.exports.module.rules || []; | ||
module.exports.module.rules.unshift({ | ||
test: /\.(js|tsx?)$/, | ||
use: [ | ||
{ | ||
loader: "swc-loader" | ||
} | ||
] | ||
}); | ||
module.exports.optimization = { | ||
minimizer: [new TerserPlugin({ | ||
minify: TerserPlugin.swcMinify, | ||
})], | ||
}; | ||
`; |