-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
123 lines (116 loc) · 2.77 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// rollup.config.js
import typescript from '@rollup/plugin-typescript';
// import typescript from 'rollup-plugin-typescript2';
import resolve from '@rollup/plugin-node-resolve';
import terser from "@rollup/plugin-terser";
import path from 'path';
const packageJson = require("./package.json");
const fs = require('fs');
const plugins = [
resolve(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
exclude: ["node_modules", "**/*.test.ts", "dist", "build", "devserver/**/*"],
}),
terser({
mangle: false,
}),
]
const getComponentsFoldersRecursive = (entry) => {
const finalListOfDirs = [];
const dirs = fs.readdirSync(entry)
while (dirs.length !== 0){
const length = dirs.length;
for(let i=0; i < length; i++){
const dir = dirs.shift();
if(fs.statSync(path.resolve(entry, dir)).isDirectory()){
if (entry === './src') {
finalListOfDirs.push(dir);
} else {
finalListOfDirs.push(path.join(entry, dir));
}
const subDirs = fs.readdirSync(path.resolve(entry, dir));
dirs.push(...subDirs.map(subDir => path.join(dir, subDir)));
}
}
}
return finalListOfDirs;
};
console.log(getComponentsFoldersRecursive('./src'));
const folderBuilds = getComponentsFoldersRecursive('./src').map((folder) => {
return {
input: `src/${folder}/index.ts`,
output: [
{
file: `build/${folder}/index.js`,
sourcemap: true,
format: 'esm',
},
// {
// file: `build/${folder}/index.cjs`,
// sourcemap: true,
// format: 'cjs',
// }
],
plugins: [
...plugins,
],
external: ['point2point'],
};
});
export default [
...folderBuilds,
// the overarching package build
{
input: 'src/index.ts',
output: [{
file: packageJson.main,
format: 'cjs',
name: '@niuee/board',
sourcemap: true,
},
{
file: packageJson.module,
format: 'esm',
name: '@niuee/board',
sourcemap: true
}
],
plugins: [
resolve(),
typescript({
tsconfig: "./tsconfig.json",
exclude: ["node_modules", "**/*.test.ts", "dist", "build", "devserver/**/*"],
declaration: true,
}),
terser({
mangle: true,
}),
],
},
{
// distribution for direct browser usage
input: 'src/index.ts',
output: [
{
file: 'dist/board.js',
format: 'esm',
name: 'board',
sourcemap: true,
},
],
plugins: [
resolve(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
exclude: ["node_modules", "**/*.test.ts", "dist", "build", "devserver/**/*"],
outDir: 'dist',
}),
terser({
mangle: false,
}),
],
}
];