refactor(repo): use turbo + rollup + vite
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { cwd } from 'process';
|
||||
import { defineConfig } from 'rollup';
|
||||
import resolvePlugin from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
|
||||
const pkg = JSON.parse(readFileSync(resolve(cwd(), './package.json')));
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
||||
const defaultPlugins = [
|
||||
resolvePlugin(),
|
||||
commonjs({
|
||||
include: /node_modules/,
|
||||
}),
|
||||
];
|
||||
|
||||
const onwarn = (warning, rollupWarn) => {
|
||||
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
|
||||
rollupWarn(warning);
|
||||
}
|
||||
};
|
||||
|
||||
export const esmConfig = defineConfig({
|
||||
input: pkg.source,
|
||||
output: {
|
||||
file: pkg.module,
|
||||
format: 'esm',
|
||||
},
|
||||
onwarn,
|
||||
plugins: [
|
||||
peerDepsExternal({
|
||||
includeDependencies: true,
|
||||
}),
|
||||
...defaultPlugins,
|
||||
typescript({
|
||||
clean: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const globals = {
|
||||
react: 'React',
|
||||
'react-dom': 'ReactDOM',
|
||||
'react/jsx-runtime': 'jsxRuntime',
|
||||
...(pkg.rollup?.globals || {}),
|
||||
};
|
||||
|
||||
export const umdConfig = defineConfig({
|
||||
input: pkg.source,
|
||||
output: {
|
||||
file: pkg.main,
|
||||
format: 'umd',
|
||||
exports: 'named',
|
||||
name: 'ReactFlow',
|
||||
globals,
|
||||
},
|
||||
onwarn,
|
||||
plugins: [
|
||||
peerDepsExternal(),
|
||||
...defaultPlugins,
|
||||
typescript({
|
||||
clean: true
|
||||
}),
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||
}),
|
||||
terser(),
|
||||
],
|
||||
});
|
||||
|
||||
export default isProd ? [esmConfig, umdConfig] : esmConfig;
|
||||
Reference in New Issue
Block a user