forked from frontend-collective/react-sortable-tree
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
67 lines (60 loc) · 1.78 KB
/
rollup.config.mjs
File metadata and controls
67 lines (60 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import postcss from "rollup-plugin-postcss";
import dts from "rollup-plugin-dts";
import { createRequire } from 'node:module';
const requireFile = createRequire(import.meta.url);
const packageJson = requireFile('./package.json');
// React Compiler is opt-in via REACT_COMPILER=true environment variable
const useReactCompiler = process.env.REACT_COMPILER === 'true';
// Conditionally load babel plugin for React Compiler
const getBabelPlugin = async () => {
if (!useReactCompiler) return null;
const { default: babel } = await import('@rollup/plugin-babel');
return babel({
babelHelpers: 'bundled',
extensions: ['.ts', '.tsx'],
plugins: [['babel-plugin-react-compiler', {}]],
});
};
export default (async () => {
const babelPlugin = await getBabelPlugin();
if (useReactCompiler) {
console.log('🚀 Building with React Compiler enabled');
}
return [{
input: "src/index.ts",
output: [
{
file: packageJson.module,
format: "esm",
sourcemap: true
}
],
external: (id) => {
if (id.includes('style-inject')) return false;
return /node_modules/.test(id);
},
plugins: [
resolve(),
commonjs(),
postcss({
extensions: ['.css']
}),
typescript({
tsconfig: './tsconfig.json',
declaration: true,
declarationDir: 'lib/types',
outDir: 'lib'
}),
// React Compiler (when enabled via REACT_COMPILER=true)
babelPlugin,
].filter(Boolean),
}, {
input: 'lib/types/index.d.ts',
output: [{ file: 'lib/index.d.ts', format: 'es' }],
plugins: [dts()],
external: [/\.css$/]
}];
})();