-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
85 lines (77 loc) · 2.09 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
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import vue from 'rollup-plugin-vue';
import { terser } from 'rollup-plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import css from 'rollup-plugin-css-only';
import fs from 'fs';
import camelCase from 'lodash/camelCase';
import upperFirst from 'lodash/upperFirst';
const genSource = (e) => `./packages/${e}/src/index.vue`;
function genConfig(input, format, {
output, name, file, useTerser,
}) {
const isUmd = format === 'umd';
return {
input: genSource(input),
output: {
dir: output,
format,
name,
file,
},
plugins: [
commonjs(),
css({ output: `${input}.css` }),
vue({ css: false }),
babel({
babelHelpers: 'bundled',
extensions: ['.js', '.vue'],
plugins: isUmd ? ['babel-plugin-transform-dynamic-imports-to-static-imports'] : [],
}),
useTerser ? terser({}) : false,
isUmd ? nodeResolve({
resolveOnly: [/^@onemin-table\/.*$/, 'lodash', 'camelcase'],
}) : false,
].filter(Boolean),
watch: {
include: 'packages/**',
},
};
}
function genSharedConfig() {
const dir = './packages/shared';
return {
input: `${dir}/src/index.js`,
output: {
dir: `${dir}/lib`,
format: 'cjs',
},
plugins: [
babel({
babelHelpers: 'bundled',
extensions: ['.js'],
}),
],
watch: {
include: `${dir}/src/**`,
},
};
}
const pkgs = fs.readdirSync('./packages')
.filter((e) => fs.lstatSync(`${__dirname}/packages/${e}`).isDirectory());
const conf = pkgs.map((e) => ((e === 'shared' || e.endsWith('utils')) ? [] : [
genConfig(e, 'cjs', { output: `./packages/${e}/lib` }),
genConfig(e, 'es', { output: `./packages/${e}/es` }),
genConfig(e, 'umd', {
name: upperFirst(camelCase(e)),
file: `./packages/${e}/dist/${e}.js`,
}),
genConfig(e, 'umd', {
name: upperFirst(camelCase(e)),
file: `./packages/${e}/dist/${e}.min.js`,
useTerser: true,
}),
genSharedConfig(),
])).flat();
export default conf;