-
TSX Browser Compiler
-
diff --git a/rollup.config.pages.ts b/rollup.config.pages.ts
index 8c413ec..2dc1866 100644
--- a/rollup.config.pages.ts
+++ b/rollup.config.pages.ts
@@ -13,6 +13,14 @@ import ts from 'typescript';
import packageJson from './package.json';
const BASEDIR = process.env.BASEDIR || '.cache';
+const reactFile = process.env.NODE_ENV === 'production' ? 'production.min' : 'development';
+
+const globals = {
+ typescript: 'ts',
+ react: 'React',
+ 'react-dom': 'ReactDOM',
+ 'react-dom/client': 'ReactDOM',
+};
const plugins = [
less({
@@ -27,6 +35,7 @@ const plugins = [
TSX Browser Compiler Playground
+
-
+
+
+
@@ -64,21 +75,8 @@ const plugins = [
swc({
minify: process.env.NODE_ENV === 'production',
sourceMaps: process.env.NODE_ENV !== 'production',
- jsc: {
- parser: {
- syntax: 'typescript',
- },
- transform: {
- react: { runtime: 'automatic' },
- },
- target: 'es2020',
- loose: true,
- keepClassNames: true,
- },
- }),
- externalGlobals({
- typescript: 'ts',
}),
+ externalGlobals(globals),
];
if (process.env.NODE_ENV !== 'production') {
@@ -102,11 +100,9 @@ export default {
file: `${BASEDIR}/index.js`,
name: 'Playground',
format: 'umd',
- globals: {
- react: 'React',
- 'react-dom': 'ReactDOM',
- },
+ globals,
sourcemap: process.env.NODE_ENV !== 'production',
},
+ external: Object.keys(globals),
plugins,
};
diff --git a/rollup.config.ts b/rollup.config.ts
new file mode 100644
index 0000000..d5bf7d3
--- /dev/null
+++ b/rollup.config.ts
@@ -0,0 +1,44 @@
+import commonjs from '@rollup/plugin-commonjs';
+import replace from '@rollup/plugin-replace';
+import resolve from '@rollup/plugin-node-resolve';
+import swc from 'rollup-plugin-swc';
+
+import packageJson from './package.json';
+
+const plugins = [
+ resolve({
+ preferBuiltins: true,
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
+ }),
+ commonjs(),
+ replace({
+ values: {
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
+ __VERSION__: JSON.stringify(packageJson.version),
+ },
+ preventAssignment: true,
+ }),
+ swc({
+ minify: process.env.NODE_ENV === 'production',
+ sourceMaps: process.env.NODE_ENV !== 'production',
+ }),
+];
+
+const globals = {
+ 'react': 'React',
+ 'react-dom': 'ReactDOM',
+ 'react/jsx-runtime': 'jsx',
+ 'typescript': 'ts',
+};
+
+export default {
+ input: {
+ index: 'src/index.ts',
+ },
+ output: [
+ { dir: './dist', format: 'esm', globals, exports: 'auto' },
+ { dir: './dist/cjs', format: 'cjs', globals, exports: 'auto' },
+ ],
+ external: Object.keys(globals),
+ plugins,
+};
diff --git a/src/index.ts b/src/index.ts
index b083ce6..7878bc6 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -9,6 +9,9 @@ import { parseSources } from './utils/loaders';
export type * from './types';
+declare const __VERSION__: string;
+export const VERSION = __VERSION__;
+
const errNoCode = new Error('No code emitted.');
const ignoredCode = [
2307,