Skip to content

Commit

Permalink
feat: add swc env minimize benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Burhanuddin Udaipurwala committed Jun 21, 2023
1 parent 35e8fba commit e54330e
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions addons/swc-env-minimize.js
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,
})],
};
`;

0 comments on commit e54330e

Please sign in to comment.