-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathrollup.config.js
45 lines (41 loc) · 2 KB
/
rollup.config.js
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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import path from 'path';
const externalDependencies = ["react", "react-dom", "react-native"];
const createPlugins = (exclude) => [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({ tsconfig: "./tsconfig.json", exclude }),
terser({
format: {
comments: false,
},
}),
];
const sourcemapPathTransform = (relativeSourcePath) => {
if(relativeSourcePath.includes("node_modules")) {
return relativeSourcePath
}
return relativeSourcePath.replace("../../../", "./src/");
}
const generateConfig = (input, outputDir, name, exclude = []) => ({
input,
output: [
{ file: path.join(outputDir, `${name}.js`), format: "umd", name, sourcemap: true,sourcemapPathTransform },
{ file: path.join(outputDir, `${name}.mjs`), format: "es", sourcemap: true, sourcemapPathTransform },
],
plugins: createPlugins(exclude),
external: externalDependencies,
});
export default [
generateConfig('./index.ts', './lib/flagsmith', 'index', ['./react.tsx', './isomorphic.ts', './index.react-native.ts']),
generateConfig('./isomorphic.ts', './lib/flagsmith', 'isomorphic', ['./react/index.ts', './index.react-native.ts']),
generateConfig('./next-middleware.ts', './lib/flagsmith', 'next-middleware', ['./react.tsx', './index.react-native.ts']),
generateConfig('./react.tsx', './lib/flagsmith', 'react', ['./index.ts', './types.ts', './isomorphic.ts', './index.react-native.ts']),
generateConfig('./react.tsx', './lib/react-native-flagsmith', 'react', ['./index.ts', './types.ts', './isomorphic.ts', './index.react-native.ts']),
generateConfig('./index.react-native.ts', './lib/react-native-flagsmith', 'index', ['./react/**', './isomorphic.ts', './index.react-native.ts']),
];