forked from siphomateke/huawei-router-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
100 lines (90 loc) · 2.21 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
import path from 'path';
import alias from 'rollup-plugin-alias';
import babel from 'rollup-plugin-babel';
import pkg from './package.json';
import sourcemaps from 'rollup-plugin-sourcemaps';
function resolve(dir) {
return path.join(__dirname, dir);
}
const formats = ['cjs', 'es'];
const builds = {
'web': {
outputFile: 'browser',
plugins: [
babel({
babelrc: false,
presets: [
['env', {
targets: {
browsers: ['last 2 versions', 'safari >= 7'],
},
modules: false,
}],
],
plugins: [
'external-helpers',
['transform-runtime', {
'polyfill': false,
'regenerator': true,
}],
],
runtimeHelpers: true,
}),
],
},
'node': {
outputFile: 'index',
plugins: [
babel({
babelrc: false,
presets: [
['env', {
targets: {node: '6.0.0'},
modules: false,
}],
],
plugins: [
'external-helpers',
],
}),
],
},
};
const external = Object.keys(pkg.dependencies);
external.push(...[
'url',
'babel-runtime/regenerator',
'babel-runtime/helpers/asyncToGenerator',
'babel-runtime/helpers/classCallCheck',
'babel-runtime/helpers/createClass',
'babel-runtime/helpers/possibleConstructorReturn',
'babel-runtime/helpers/inherits',
'babel-runtime/helpers/typeof',
]);
function getConfig() {
const config = {
input: 'src/index.js',
plugins: [sourcemaps()],
external,
};
const option = builds[process.env.TARGET.split('-')[1]];
const isBrowser = process.env.TARGET.includes('web');
const buildType = isBrowser ? 'browser' : 'node';
config.plugins = config.plugins.concat(option.plugins);
config.plugins.push(alias({
'@': resolve('src'),
'$env': resolve(`src/${buildType}`),
}));
config.output = [];
for (let format of formats) {
const output = {};
output.file = resolve(`dist/${option.outputFile}.${format}.js`);
output.format = format;
if (process.env.TARGET.includes('dev')) {
output.sourcemap = true;
}
config.output.push(output);
}
return config;
}
export default getConfig();