-
Notifications
You must be signed in to change notification settings - Fork 26
/
rollup.config.js
127 lines (121 loc) · 2.7 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
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import buble from '@rollup/plugin-buble'
import babel from '@rollup/plugin-babel'
import { terser } from 'rollup-plugin-terser'
const pkg = require('./package.json')
const externalModules = [
'dns',
'fs',
'path',
'url',
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {})
]
const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`)
const externalTest = (id) => {
if (id === 'babel-plugin-transform-async-to-promises/helpers') {
return false
}
return externalPredicate.test(id)
}
const plugins = [
babel({
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [],
plugins: ['@babel/plugin-transform-flow-strip-types']
}),
resolve({
dedupe: externalModules,
mainFields: ['module', 'jsnext', 'main'],
browser: true
}),
commonjs({
ignoreGlobal: true,
include: /\/node_modules\//,
namedExports: {
react: Object.keys(require('react'))
}
}),
buble({
transforms: {
unicodeRegExp: false,
dangerousForOf: true,
dangerousTaggedTemplateString: true
},
objectAssign: 'Object.assign',
exclude: 'node_modules/**'
}),
babel({
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [],
plugins: [
'babel-plugin-closure-elimination',
'@babel/plugin-transform-object-assign',
[
'babel-plugin-transform-async-to-promises',
{
inlineHelpers: true,
externalHelpers: true
}
]
]
}),
terser({
warnings: true,
ecma: 5,
keep_fnames: true,
ie8: false,
compress: {
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: {
module: true,
keep_fnames: true
},
output: {
beautify: true,
braces: true,
indent_level: 2
}
})
]
export default {
input: './src/index.js',
onwarn: () => {},
external: externalTest,
treeshake: {
propertyReadSideEffects: false
},
plugins,
output: [
{
sourcemap: true,
freeze: false,
// NOTE: *.mjs files will lead to issues since react is still a non-ESM package
// the same goes for package.json:exports
file: './dist/react-ssr-prepass.es.js',
format: 'esm'
},
{
sourcemap: true,
freeze: false,
file: './dist/react-ssr-prepass.js',
format: 'cjs'
}
]
}