From 419310cd15673d1c3d4112cbedf85ea08c1c1e61 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Fri, 27 Oct 2023 14:07:56 -0400 Subject: [PATCH] Bundle babel-plugin-react-forget with rollup Attempt to bundle the plugin with rollup instead of just tsc. I'm intentionally not inlining babel related modules, as we should ideally rely on the host environment's version instead --- .../babel-plugin-react-forget/package.json | 2 +- .../rollup.config.js | 32 +++++++++++++++++++ .../babel-plugin-react-forget/tsconfig.json | 3 +- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 compiler/packages/babel-plugin-react-forget/rollup.config.js diff --git a/compiler/packages/babel-plugin-react-forget/package.json b/compiler/packages/babel-plugin-react-forget/package.json index 4b5cabc25f..43a7d5dd73 100644 --- a/compiler/packages/babel-plugin-react-forget/package.json +++ b/compiler/packages/babel-plugin-react-forget/package.json @@ -8,7 +8,7 @@ "src" ], "scripts": { - "build": "rimraf dist && tsc", + "build": "rimraf dist && rollup --config --bundleConfigAsCjs", "test": "concurrently -g -n snap,sprout \"yarn snap:ci\" \"yarn sprout:ci\"", "jest": "tsc && ts-node \"$(yarn --silent which jest)\"", "snap": "node ../snap/dist/main.js", diff --git a/compiler/packages/babel-plugin-react-forget/rollup.config.js b/compiler/packages/babel-plugin-react-forget/rollup.config.js new file mode 100644 index 0000000000..54eca56f80 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/rollup.config.js @@ -0,0 +1,32 @@ +import typescript from "@rollup/plugin-typescript"; +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import path from "path"; +import process from "process"; + +const NO_INLINE = new Set(["@babel/generator", "@babel/types"]); + +export default { + input: "src/index.ts", + output: { + file: "dist/index.js", + format: "cjs", + sourcemap: false, + exports: "named", + }, + plugins: [ + typescript({ + compilerOptions: { + noEmit: true, + }, + }), + json(), + nodeResolve({ + preferBuiltins: true, + resolveOnly: (module) => NO_INLINE.has(module) === false, + rootDir: path.join(process.cwd(), ".."), + }), + commonjs(), + ], +}; diff --git a/compiler/packages/babel-plugin-react-forget/tsconfig.json b/compiler/packages/babel-plugin-react-forget/tsconfig.json index d487abc908..692168976d 100644 --- a/compiler/packages/babel-plugin-react-forget/tsconfig.json +++ b/compiler/packages/babel-plugin-react-forget/tsconfig.json @@ -16,8 +16,7 @@ "target": "ES2015", // ideally turn off only during dev, or on a per-file basis "noUnusedLocals": false, - "sourceMap": true, - "composite": true + "composite": true, }, "exclude": [ "node_modules",