Skip to content

Commit

Permalink
[Build] Allow external classes (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
redstonekasi authored Mar 8, 2023
1 parent 7ff931b commit 4d77bea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
47 changes: 32 additions & 15 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,40 @@ import { readFile, writeFile, readdir } from "fs/promises";
import { createHash } from "crypto";

import { rollup } from "rollup";
import { swc } from "rollup-plugin-swc3";
import esbuild from "rollup-plugin-esbuild";
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import swc from "@swc/core";

/** @type import("rollup").InputPluginOption */
const plugins = [
nodeResolve(),
commonjs(),
{
name: "swc",
async transform(code, id) {
const result = await swc.transform(code, {
filename: id,
jsc: {
externalHelpers: true,
parser: {
syntax: "typescript",
tsx: true,
},
},
env: {
targets: "defaults",
include: [
"transform-classes",
"transform-arrow-functions",
],
},
});
return result.code;
},
},
esbuild({ minify: true }),
];

for (let plug of await readdir("./plugins")) {
const manifest = JSON.parse(await readFile(`./plugins/${plug}/manifest.json`));
Expand All @@ -15,20 +45,7 @@ for (let plug of await readdir("./plugins")) {
const bundle = await rollup({
input: `./plugins/${plug}/${manifest.main}`,
onwarn: () => {},
plugins: [
nodeResolve(),
commonjs(),
esbuild({ minify: true }),
swc({
env: {
targets: "defaults",
include: [
"transform-classes",
"transform-arrow-functions",
],
},
}),
],
plugins,
});

await bundle.write({
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
"scripts": {
"build": "node build.mjs"
},
"dependencies": {
"@swc/helpers": "^0.4.14"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@swc/core": "^1.3.35",
"esbuild": "^0.16.14",
"rollup": "^3.9.1",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-swc3": "^0.8.0",
"vendetta-types": "latest"
},
"pnpm": {
Expand Down

0 comments on commit 4d77bea

Please sign in to comment.