-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
81 lines (76 loc) · 2.34 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
const fs = require('fs');
const path = require('path');
const babelPlugin = require('rollup-plugin-babel');
const json = require('@rollup/plugin-json');
//const { eslint } = require('rollup-plugin-eslint');
const cwd = process.cwd();
const PKGDIR = './packages';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
const pkgDirsNames = fs.readdirSync(PKGDIR).filter((cName) => {
const abPath = path.join(cwd, `packages/${cName}`);
return fs.statSync(abPath).isDirectory();
});
function generateConfig(pkgDirName) {
return {
input: `${PKGDIR}/${pkgDirName}/src/index.js`,
output: [
// {
// file: `${PKGDIR}/${pkgDirName}/esm/index.esm.js`,
// format: 'esm'
// },
{
file: `${PKGDIR}/${pkgDirName}/dist/index.js`,
format: 'esm'
}
],
external: [
'@sniperjs/error-reporter',
'@sniperjs/miniwx-error-reporter',
'@sniperjs/utils'
],
plugins: [
json(),
commonjs(),
resolve(),
babelPlugin({
exclude: 'node_modules/**',
plugins: ['@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-async-to-generator'],
}),
// eslint({
// extends: 'airbnb'
// })
],
};
}
function generateWebConfig(isBrowser, pkgDirName) {
return {
input: `${PKGDIR}/${pkgDirName}/src/index.js`,
output: [
{
file: `${PKGDIR}/${pkgDirName}/dist/index.js`,
format: isBrowser ? 'umd' : 'cjs',
name: 'Sniperjs',
},
],
plugins: [
json(),
babelPlugin({
exclude: 'node_modules/**',
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-classes',
],
}),
resolve({
browser: isBrowser,
}),
commonjs(),
],
};
}
const CONFIG = pkgDirsNames.map((cName) => {
const isWeb = cName === 'WebReporter';
return isWeb ? generateWebConfig(true, cName) : generateConfig(cName);
});
module.exports = CONFIG;