-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugins.js
50 lines (44 loc) · 1.63 KB
/
plugins.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
import json from 'rollup-plugin-json';
import nodeGlobals from 'rollup-plugin-node-globals';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import replace from '@rollup/plugin-replace';
import sourcemaps from 'rollup-plugin-sourcemaps';
// import compiler from '@ampproject/rollup-plugin-closure-compiler';
import { terser } from './packages/terser';
import { sizeme } from './packages/sizeme';
import { servor } from './packages/servor';
import { babelConfig } from './babel';
const plugins = (command, pkg, options) => {
const { extensions, presets, plugins } = babelConfig(command, pkg, options);
const { sourcemap, minify, fallback, port, namedExports, closure } = options;
const babelDefaults = { babelrc: false, configFile: false, compact: false };
return [
sourcemap && sourcemaps(),
json(),
nodeGlobals(),
nodeResolve({
mainFields: ['module', 'jsnext:main', 'browser', 'main'],
extensions,
}),
commonjs({ extensions, include: /\/node_modules\//, namedExports }),
babel({
...babelDefaults,
exclude: 'node_modules/**',
extensions,
presets,
plugins,
}),
replace({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }),
command !== 'start' &&
minify &&
(closure
? // ? compiler({ compilation_level: 'ADVANCED' })
terser({ sourcemap, warnings: false })
: terser({ sourcemap, warnings: false })),
command !== 'start' && sizeme(),
command === 'start' && servor({ fallback, port }),
].filter(Boolean);
};
export { plugins };