-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
147 lines (134 loc) · 3.01 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import dts from "rollup-plugin-dts";
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,
// useTsconfigDeclarationDir: true,
}),
terser({
mangle: false,
}),
]
export const getComponentsFolders = (entry) => {
const dirs = fs.readdirSync(entry)
const dirsWithoutIndex = dirs.filter(name => name !== 'index.ts' && name !== 'utils')
return dirsWithoutIndex
};
export 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',
},
],
plugins: [
...plugins,
]
};
});
const types = getComponentsFoldersRecursive('./src').map((folder) => {
return {
input: `src/${folder}/index.ts`,
output: {
file: `build/${folder}/index.d.ts`,
format: "es",
},
plugins: [
dts.default(),
],
};
});
export default [
...folderBuilds,
{
input: 'src/index.ts',
output: [{
file: packageJson.main,
format: 'cjs',
name: '@niuee/bolt',
sourcemap: true,
},
{
file: packageJson.module,
format: 'esm',
name: '@niuee/bolt',
sourcemap: true
}
],
plugins: [
resolve(),
typescript({
tsconfig: './tsconfig.json',
declaration: true,
declarationDir: "./build",
}),
terser({
mangle: false,
}),
],
},
{
// distribution for direct browser usage
input: 'src/index.ts',
output: [
{
file: 'dist/bolt.js',
format: 'esm',
sourcemap: true,
},
{
file: 'build/umd/index.js',
format: 'umd',
name: "Bolt",
sourcemap: true
},
{
file: 'build/iife/index.js',
format: 'iife',
name: "Bolt",
sourcemap: true
}
],
plugins: [
resolve(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
}),
terser({
mangle: false,
}),
],
}
];