-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-builder.js
More file actions
executable file
·58 lines (53 loc) · 1.57 KB
/
Copy pathbundle-builder.js
File metadata and controls
executable file
·58 lines (53 loc) · 1.57 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
#!/usr/bin/env node
const rollup = require('rollup');
const resolve = require('@rollup/plugin-node-resolve').default;
const babel = require('@rollup/plugin-babel').default;
const postcss = require('rollup-plugin-postcss');
const url = require('@rollup/plugin-url');
const path = require('path');
const svgr = require('@svgr/rollup');
const typescript = require('rollup-plugin-typescript2');
const commonJS = require('@rollup/plugin-commonjs');
const { terser } = require('rollup-plugin-terser');
const currentWorkingPath = process.cwd();
const inputPath = path.join(currentWorkingPath, 'src/index.ts');
const inputOptions = {
input: inputPath,
external: ['react'],
plugins: [
resolve(),
postcss({
// css modules
modules: true
}),
babel({
presets: [['@babel/preset-env', { "modules": false }], '@babel/preset-react'],
babelHelpers: 'runtime',
exclude: 'node_modules/**',
}),
url(),
// export ReactComponents from svg files
svgr(),
typescript({ useTsconfigDeclarationDir: true }),
commonJS({
include: 'node_modules/**'
}),
terser()
],
};
const outputOptions = [
{
dir: `dist`,
format: 'esm',
preserveModules: true,
},
];
async function build() {
// create bundle
const bundle = await rollup.rollup(inputOptions);
// loop through the options and write individual bundles
outputOptions.forEach(async (options) => {
await bundle.write(options);
});
}
build();