Skip to content

Commit

Permalink
Merge pull request #5 from burhanuday/feat/add-swc-minify
Browse files Browse the repository at this point in the history
feat: add swc minification for benchmarking
  • Loading branch information
TheLarkInn authored Jun 26, 2023
2 parents e138fc3 + e54330e commit a69cf83
Show file tree
Hide file tree
Showing 2 changed files with 77 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,
})],
};
`;
17 changes: 17 additions & 0 deletions addons/swc-minimize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const packageJson = (json) => {
Object.assign(json.devDependencies, {
"terser-webpack-plugin": "*",
});
return json;
};

export const config = (content) => `${content}
var TerserPlugin = require("terser-webpack-plugin");
module.exports.optimization = {
minimizer: [new TerserPlugin({
minify: TerserPlugin.swcMinify,
})],
};
`;

0 comments on commit a69cf83

Please sign in to comment.