feat(package): add umd version
This commit is contained in:
+103
-62
@@ -7,6 +7,7 @@ import svgr from '@svgr/rollup';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import { DEFAULT_EXTENSIONS as DEFAULT_BABEL_EXTENSIONS } from '@babel/core';
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
|
||||
import pkg from './package.json';
|
||||
|
||||
@@ -14,74 +15,114 @@ const isProd = process.env.NODE_ENV === 'production';
|
||||
const isTesting = process.env.NODE_ENV === 'testing';
|
||||
const processEnv = isProd || isTesting ? 'production' : 'development';
|
||||
|
||||
export const baseConfig = ({ outputDir = 'dist/esm', injectCSS = true } = {}) => ({
|
||||
input: [
|
||||
'src/index.ts',
|
||||
'src/additional-components/Controls/index.tsx',
|
||||
'src/additional-components/Background/index.tsx',
|
||||
'src/additional-components/MiniMap/index.tsx',
|
||||
'src/hooks/useReactFlow.ts',
|
||||
'src/hooks/useNodes.ts',
|
||||
'src/hooks/useEdges.ts',
|
||||
'src/hooks/useViewport.ts',
|
||||
'src/hooks/useUpdateNodeInternals.ts',
|
||||
],
|
||||
external: [
|
||||
'react',
|
||||
'react-dom',
|
||||
'classcat',
|
||||
'd3-selection',
|
||||
'd3-zoom',
|
||||
'react-draggable',
|
||||
'zustand',
|
||||
'zustand/shallow',
|
||||
'zustand/context',
|
||||
(id) => id.includes('@babel/runtime'),
|
||||
],
|
||||
onwarn(warning, rollupWarn) {
|
||||
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
|
||||
rollupWarn(warning);
|
||||
}
|
||||
},
|
||||
output: {
|
||||
dir: outputDir,
|
||||
format: 'esm',
|
||||
sourcemap: true,
|
||||
},
|
||||
const defaultOutputOptions = {
|
||||
dir: 'dist/esm',
|
||||
format: 'esm',
|
||||
sourcemap: true,
|
||||
};
|
||||
|
||||
plugins: [
|
||||
replace({
|
||||
__ENV__: JSON.stringify(processEnv),
|
||||
__REACT_FLOW_VERSION__: JSON.stringify(pkg.version),
|
||||
__INJECT_STYLES__: injectCSS,
|
||||
preventAssignment: true,
|
||||
}),
|
||||
postcss({
|
||||
minimize: isProd,
|
||||
inject: false,
|
||||
}),
|
||||
svgr(),
|
||||
resolve(),
|
||||
typescript({
|
||||
clean: true,
|
||||
}),
|
||||
commonjs({
|
||||
include: 'node_modules/**',
|
||||
}),
|
||||
babel({
|
||||
extensions: [...DEFAULT_BABEL_EXTENSIONS, '.ts', '.tsx'],
|
||||
exclude: 'node_modules/**',
|
||||
babelHelpers: 'runtime',
|
||||
}),
|
||||
visualizer(),
|
||||
],
|
||||
});
|
||||
export const baseConfig = ({ outputOptions = {}, injectCSS = true } = {}) => {
|
||||
const output = {
|
||||
...defaultOutputOptions,
|
||||
...outputOptions,
|
||||
};
|
||||
|
||||
const isEsm = output.format === 'esm';
|
||||
const replaceOptions = isEsm ? {} : { 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) };
|
||||
|
||||
return {
|
||||
input: isEsm
|
||||
? [
|
||||
'src/index.ts',
|
||||
'src/additional-components/Controls/index.tsx',
|
||||
'src/additional-components/Background/index.tsx',
|
||||
'src/additional-components/MiniMap/index.tsx',
|
||||
'src/hooks/useReactFlow.ts',
|
||||
'src/hooks/useNodes.ts',
|
||||
'src/hooks/useEdges.ts',
|
||||
'src/hooks/useViewport.ts',
|
||||
'src/hooks/useUpdateNodeInternals.ts',
|
||||
]
|
||||
: 'src/index.ts',
|
||||
external: isEsm
|
||||
? [
|
||||
'react',
|
||||
'react-dom',
|
||||
'classcat',
|
||||
'd3-selection',
|
||||
'd3-zoom',
|
||||
'react-draggable',
|
||||
'zustand',
|
||||
'zustand/shallow',
|
||||
'zustand/context',
|
||||
(id) => id.includes('@babel/runtime'),
|
||||
]
|
||||
: ['react', 'react-dom'],
|
||||
onwarn(warning, rollupWarn) {
|
||||
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
|
||||
rollupWarn(warning);
|
||||
}
|
||||
},
|
||||
output,
|
||||
|
||||
plugins: [
|
||||
replace({
|
||||
__ENV__: JSON.stringify(processEnv),
|
||||
__REACT_FLOW_VERSION__: JSON.stringify(pkg.version),
|
||||
__INJECT_STYLES__: injectCSS,
|
||||
preventAssignment: true,
|
||||
...replaceOptions,
|
||||
}),
|
||||
postcss({
|
||||
minimize: isProd,
|
||||
inject: false,
|
||||
}),
|
||||
svgr(),
|
||||
resolve(),
|
||||
typescript({
|
||||
clean: true,
|
||||
}),
|
||||
commonjs({
|
||||
include: 'node_modules/**',
|
||||
}),
|
||||
babel({
|
||||
extensions: [...DEFAULT_BABEL_EXTENSIONS, '.ts', '.tsx'],
|
||||
exclude: 'node_modules/**',
|
||||
babelHelpers: 'runtime',
|
||||
}),
|
||||
visualizer(),
|
||||
!isEsm && terser(),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
export default isProd && !isTesting
|
||||
? [
|
||||
baseConfig(),
|
||||
baseConfig({
|
||||
outputDir: 'dist/nocss',
|
||||
outputOptions: {
|
||||
dir: 'dist/umd',
|
||||
format: 'umd',
|
||||
exports: 'named',
|
||||
name: 'ReactFlow',
|
||||
globals: {
|
||||
react: 'React',
|
||||
'react-dom': 'ReactDOM',
|
||||
classcat: 'cc',
|
||||
'd3-selection': 'd3',
|
||||
'd3-zoom': 'd3',
|
||||
'react-draggable': 'ReactDraggable',
|
||||
zustand: 'zustand',
|
||||
'zustand/shallow': 'zustandShallow',
|
||||
'zustand/context': 'zustandContext',
|
||||
},
|
||||
},
|
||||
}),
|
||||
baseConfig({
|
||||
outputOptions: {
|
||||
dir: 'dist/nocss',
|
||||
},
|
||||
|
||||
injectCSS: false,
|
||||
}),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user