-
Notifications
You must be signed in to change notification settings - Fork 14
/
rollup.config.js
138 lines (124 loc) · 3.07 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
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import buble from '@rollup/plugin-buble';
import babel from 'rollup-plugin-babel';
import { terser } from 'rollup-plugin-terser';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
const pkg = require('./package.json');
export const externalModules = ['dns', 'fs', 'path', 'url'];
if (pkg.peerDependencies)
externalModules.push(...Object.keys(pkg.peerDependencies));
if (pkg.dependencies) externalModules.push(...Object.keys(pkg.dependencies));
const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`);
export const isExternal = id => {
if (id === 'babel-plugin-transform-async-to-promises/helpers') return false;
return externalPredicate.test(id);
};
const config = {
input: {
[pkg.name]: './src/index.ts',
},
onwarn() {},
external: isExternal,
treeshake: {
unknownGlobalSideEffects: false,
tryCatchDeoptimization: false,
moduleSideEffects: false,
},
};
const plugins = [
resolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
mainFields: ['module', 'jsnext', 'main'],
preferBuiltins: false,
browser: true,
}),
commonjs({
ignoreGlobal: true,
include: /\/node_modules\//,
namedExports: {},
}),
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
sourceMap: true,
noEmit: false,
declaration: true,
declarationDir: './dist/types',
target: 'esnext',
},
},
}),
buble({
transforms: {
unicodeRegExp: false,
dangerousForOf: true,
dangerousTaggedTemplateString: true,
asyncAwait: false,
},
objectAssign: 'Object.assign',
}),
babel({
babelrc: false,
extensions: ['js', 'jsx', 'ts', 'tsx'],
presets: [],
plugins: [
'babel-plugin-closure-elimination',
'@babel/plugin-transform-object-assign',
].filter(Boolean),
}),
compiler({
formatting: 'PRETTY_PRINT',
compilation_level: 'SIMPLE_OPTIMIZATIONS',
}),
terser({
warnings: true,
ecma: 5,
keep_fnames: true,
ie8: false,
compress: {
hoist_vars: false,
hoist_funs: false,
pure_getters: true,
toplevel: true,
booleans_as_integers: false,
keep_fnames: true,
keep_fargs: true,
if_return: false,
ie8: false,
sequences: false,
loops: false,
conditionals: false,
join_vars: false,
},
mangle: false,
output: {
beautify: true,
braces: true,
indent_level: 2,
},
}),
];
const output = (format = 'cjs', extension = '.js') => ({
chunkFileNames: '[hash]' + extension,
entryFileNames: '[name]' + extension,
dir: './dist',
exports: 'named',
externalLiveBindings: false,
sourcemap: true,
esModule: false,
indent: false,
freeze: false,
strict: false,
format,
});
export default [
{
...config,
shimMissingExports: true,
plugins,
output: [output('esm', '.es.js'), output('cjs', '.js')],
},
];