Skip to content

Commit c7d18a3

Browse files
committed
Replace microbundle with custom rollup config
1 parent 6510fdf commit c7d18a3

File tree

3 files changed

+449
-2405
lines changed

3 files changed

+449
-2405
lines changed

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "1.0.6",
44
"description": "A custom partial React SSR renderer for prefetching and suspense",
55
"main": "index.js",
6-
"source": "src/index.js",
76
"author": "Phil Plückthun <phil.pluckthun@formidable.com>",
87
"license": "MIT",
98
"repository": "git@github.com:FormidableLabs/react-ssr-prepass.git",
@@ -17,9 +16,7 @@
1716
],
1817
"scripts": {
1918
"prepublishOnly": "run-s build",
20-
"build:prod": "microbundle --target node -f cjs --compress --define '__DEV__=false' -o dist/react-ssr-prepass.production.min.js",
21-
"build:dev": "microbundle --target node -f cjs --no-compress --define '__DEV__=true' -o dist/react-ssr-prepass.development.js",
22-
"build": "run-p build:prod build:dev",
19+
"build": "rollup -c rollup.config.js",
2320
"test": "jest",
2421
"flow": "flow"
2522
},
@@ -65,21 +62,30 @@
6562
},
6663
"devDependencies": {
6764
"@babel/core": "^7.5.5",
65+
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
66+
"@babel/plugin-transform-object-assign": "^7.2.0",
6867
"@babel/preset-env": "^7.5.5",
6968
"@babel/preset-flow": "^7.0.0",
7069
"@babel/preset-react": "^7.0.0",
70+
"babel-plugin-closure-elimination": "^1.3.0",
71+
"babel-plugin-transform-async-to-promises": "^0.8.14",
7172
"codecov": "^3.5.0",
7273
"flow-bin": "^0.106.3",
7374
"husky": "^3.0.5",
7475
"jest": "^24.9.0",
7576
"lint-staged": "^9.2.5",
76-
"microbundle": "^0.11.0",
7777
"npm-run-all": "^4.1.5",
7878
"prettier": "^1.18.2",
7979
"react": "^16.9.0",
8080
"react-dom": "^16.9.0",
8181
"react-is": "^16.9.0",
8282
"rollup": "^1.20.3",
83+
"rollup-plugin-babel": "^4.3.3",
84+
"rollup-plugin-buble": "^0.19.8",
85+
"rollup-plugin-commonjs": "^10.1.0",
86+
"rollup-plugin-node-resolve": "^5.2.0",
87+
"rollup-plugin-replace": "^2.2.0",
88+
"rollup-plugin-terser": "^5.1.1",
8389
"styled-components": "^4.3.2"
8490
}
8591
}

rollup.config.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import commonjs from 'rollup-plugin-commonjs'
2+
import nodeResolve from 'rollup-plugin-node-resolve'
3+
import buble from 'rollup-plugin-buble'
4+
import babel from 'rollup-plugin-babel'
5+
import { terser } from 'rollup-plugin-terser'
6+
import replace from 'rollup-plugin-replace'
7+
8+
const pkgInfo = require('./package.json')
9+
const { peerDependencies, dependencies } = pkgInfo
10+
11+
let external = ['dns', 'fs', 'path', 'url']
12+
13+
if (pkgInfo.peerDependencies) {
14+
external.push(...Object.keys(peerDependencies))
15+
}
16+
17+
if (pkgInfo.dependencies) {
18+
external.push(...Object.keys(dependencies))
19+
}
20+
21+
const externalPredicate = new RegExp(`^(${external.join('|')})($|/)`)
22+
const externalTest = id => {
23+
if (id === 'babel-plugin-transform-async-to-promises/helpers') {
24+
return false
25+
}
26+
27+
return externalPredicate.test(id)
28+
}
29+
30+
const terserPretty = terser({
31+
sourcemap: true,
32+
warnings: true,
33+
ecma: 5,
34+
keep_fnames: true,
35+
ie8: false,
36+
compress: {
37+
pure_getters: true,
38+
toplevel: true,
39+
booleans_as_integers: false,
40+
keep_fnames: true,
41+
keep_fargs: true,
42+
if_return: false,
43+
ie8: false,
44+
sequences: false,
45+
loops: false,
46+
conditionals: false,
47+
join_vars: false
48+
},
49+
mangle: false,
50+
output: {
51+
beautify: true,
52+
braces: true,
53+
indent_level: 2
54+
}
55+
})
56+
57+
const terserMinified = terser({
58+
sourcemap: true,
59+
warnings: true,
60+
ecma: 5,
61+
ie8: false,
62+
toplevel: true,
63+
compress: {
64+
keep_infinity: true,
65+
pure_getters: true,
66+
passes: 10
67+
},
68+
output: {
69+
comments: false
70+
}
71+
})
72+
73+
const makePlugins = (isProduction = false) => [
74+
babel({
75+
babelrc: false,
76+
exclude: 'node_modules/**',
77+
presets: [],
78+
plugins: ['@babel/plugin-transform-flow-strip-types']
79+
}),
80+
nodeResolve({
81+
mainFields: ['module', 'jsnext', 'main'],
82+
browser: true
83+
}),
84+
commonjs({
85+
ignoreGlobal: true,
86+
include: /\/node_modules\//,
87+
namedExports: {
88+
react: Object.keys(require('react'))
89+
}
90+
}),
91+
buble({
92+
transforms: {
93+
unicodeRegExp: false,
94+
dangerousForOf: true,
95+
dangerousTaggedTemplateString: true
96+
},
97+
objectAssign: 'Object.assign',
98+
exclude: 'node_modules/**'
99+
}),
100+
babel({
101+
babelrc: false,
102+
exclude: 'node_modules/**',
103+
presets: [],
104+
plugins: [
105+
'babel-plugin-closure-elimination',
106+
'@babel/plugin-transform-object-assign',
107+
[
108+
'babel-plugin-transform-async-to-promises',
109+
{
110+
inlineHelpers: true,
111+
externalHelpers: true
112+
}
113+
]
114+
]
115+
}),
116+
isProduction &&
117+
replace({
118+
'process.env.NODE_ENV': JSON.stringify('production')
119+
}),
120+
isProduction ? terserMinified : terserPretty
121+
]
122+
123+
const config = {
124+
input: './src/index.js',
125+
onwarn: () => {},
126+
external: externalTest,
127+
treeshake: {
128+
propertyReadSideEffects: false
129+
}
130+
}
131+
132+
const name = 'react-ssr-prepass'
133+
134+
export default [
135+
{
136+
...config,
137+
plugins: makePlugins(false),
138+
output: [
139+
{
140+
sourcemap: true,
141+
legacy: true,
142+
freeze: false,
143+
esModule: false,
144+
file: `./dist/${name}.development.js`,
145+
format: 'cjs'
146+
}
147+
]
148+
},
149+
{
150+
...config,
151+
plugins: makePlugins(true),
152+
output: [
153+
{
154+
sourcemap: true,
155+
legacy: true,
156+
freeze: false,
157+
file: `./dist/${name}.production.min.js`,
158+
format: 'cjs'
159+
}
160+
]
161+
}
162+
]

0 commit comments

Comments
 (0)