Skip to content

Instantly share code, notes, and snippets.

@DrSensor
Created December 2, 2024 17:16
Show Gist options
  • Save DrSensor/09fbec06f1b49627d48faace2dd03d69 to your computer and use it in GitHub Desktop.
Save DrSensor/09fbec06f1b49627d48faace2dd03d69 to your computer and use it in GitHub Desktop.
Rolldown config with swc for advanced mangling and esbuild for minification
// @ts-check
/** @import { RolldownOptions, OutputOptions, Plugin } from "rolldown" */
import isolatedDeclarations from "@unplugin/isolated-decl/rolldown"
import swc from "unplugin-swc"
import * as esbuild from "rollup-plugin-esbuild"
const /** @satisfies {OutputOptions} */ output = {
chunkFileNames: "[name].js",
sourcemap: true,
}
const /** @satisfies {RolldownOptions} */ module = {
input: "./module.ts",
output,
plugins: [isolatedDeclarations({ transformer: "oxc" })],
}
const /** @satisfies {RolldownOptions} */ script = {
input: "./script.ts",
output,
plugins: [
swc.rolldown({
tsconfigFile: "./deno.json",
jsc: {
target: "esnext",
externalHelpers: true,
transform: {
constModules: {}, // TODO: inline error code
optimizer: {
simplify: true,
globals: {
vars: {},
typeofs: {}, // NOTE: may make code readable and eliminate some helper in internal.js
},
},
treatConstEnumAsEnum: false,
},
minify: {
compress: {
booleans_as_integers: true,
reduce_funcs: true,
unsafe: true,
},
mangle: {
props: {
reserved: [],
undeclared: true,
regex: /_$/.source,
},
},
},
},
}),
/** @type {Plugin} */ (esbuild.minify()),
],
}
export default [module, script]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment