|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import commonjs from '@rollup/plugin-commonjs'; |
18 | 17 | import resolve from '@rollup/plugin-node-resolve'; |
19 | | -import replace from '@rollup/plugin-replace'; |
20 | 18 | import terser from '@rollup/plugin-terser'; |
21 | 19 | import pkg from './package.json' with { type: 'json' }; |
22 | 20 |
|
23 | 21 | const { dependencies, peerDependencies } = pkg; |
24 | 22 | const external = [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {}), 'crypto']; |
25 | 23 |
|
26 | | -const cjsBundle = (minify = true) => ({ |
| 24 | +export default { |
27 | 25 | input: '.build/index.js', |
28 | 26 | external, |
29 | | - plugins: [resolve({ browser: true }), commonjs(), minify && terser()].filter(Boolean), |
| 27 | + plugins: [resolve({ browser: true }), terser()], |
30 | 28 | output: { |
31 | | - file: `dist/react-sdk${minify ? '.min' : ''}.js`, |
32 | | - format: 'cjs', |
33 | | - exports: 'named', |
34 | | - sourcemap: true, |
35 | | - globals: { react: 'React' }, |
36 | | - }, |
37 | | -}); |
38 | | - |
39 | | -const esmBundle = (minify = true) => ({ |
40 | | - input: '.build/index.js', |
41 | | - external, |
42 | | - plugins: [resolve({ browser: true }), commonjs(), minify && terser()].filter(Boolean), |
43 | | - output: { |
44 | | - file: `dist/react-sdk.es${minify ? '.min' : ''}.js`, |
| 29 | + file: 'dist/react-sdk.es.min.js', |
45 | 30 | format: 'es', |
46 | 31 | sourcemap: true, |
47 | 32 | }, |
48 | | -}); |
49 | | - |
50 | | -const umdBundle = (minify = true) => ({ |
51 | | - input: '.build/index.js', |
52 | | - external: ['react'], |
53 | | - plugins: [ |
54 | | - resolve({ browser: true }), |
55 | | - commonjs(), |
56 | | - replace({ |
57 | | - 'process.env.NODE_ENV': JSON.stringify('production'), |
58 | | - preventAssignment: true, |
59 | | - }), |
60 | | - minify && terser(), |
61 | | - ].filter(Boolean), |
62 | | - output: { |
63 | | - file: `dist/react-sdk.umd${minify ? '.min' : ''}.js`, |
64 | | - format: 'umd', |
65 | | - name: 'optimizelyReactSdk', |
66 | | - exports: 'named', |
67 | | - sourcemap: true, |
68 | | - globals: { react: 'React' }, |
69 | | - }, |
70 | | -}); |
71 | | - |
72 | | -const bundles = { |
73 | | - 'cjs-min': cjsBundle(true), |
74 | | - cjs: cjsBundle(false), |
75 | | - 'esm-min': esmBundle(true), |
76 | | - esm: esmBundle(false), |
77 | | - 'umd-min': umdBundle(true), |
78 | | - umd: umdBundle(false), |
79 | | -}; |
80 | | - |
81 | | -export default (args) => { |
82 | | - const patterns = Object.keys(args) |
83 | | - .filter((arg) => arg.startsWith('config-')) |
84 | | - .map((arg) => arg.replace(/config-/, '')); |
85 | | - |
86 | | - if (!patterns.length) { |
87 | | - // Default: build minified versions only |
88 | | - return [bundles['cjs-min'], bundles['esm-min'], bundles['umd-min']]; |
89 | | - } |
90 | | - |
91 | | - return Object.entries(bundles) |
92 | | - .filter(([name]) => patterns.some((pattern) => name.match(pattern))) |
93 | | - .map(([, config]) => config); |
94 | 33 | }; |
0 commit comments