-
-
Notifications
You must be signed in to change notification settings - Fork 303
/
rollup.config.js
98 lines (90 loc) · 2.63 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
const builtinModules = require('module').builtinModules;
const execSync = require('child_process').execSync;
const babel = require('rollup-plugin-babel');
const commonjs = require('rollup-plugin-commonjs');
const compiler = require('@ampproject/rollup-plugin-closure-compiler');
const json = require('rollup-plugin-json');
const replace = require('rollup-plugin-replace');
const resolve = require('rollup-plugin-node-resolve');
const url = require('rollup-plugin-url');
const entryManifest = require('./plugins/entryManifest');
const pkg = require('./package.json');
const buildId =
process.env.BUILD_ID ||
execSync('git rev-parse --short HEAD').toString().trim();
const manifest = entryManifest();
const client = ['browse', 'main'].map(entryName => {
return {
external: ['@emotion/core', 'react', 'react-dom'],
input: `modules/client/${entryName}.js`,
output: {
format: 'iife',
dir: 'public/_client',
entryFileNames: '[name]-[hash].js',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@emotion/core': 'emotionCore'
}
},
moduleContext: {
'node_modules/react-icons/lib/esm/iconBase.js': 'window'
},
plugins: [
manifest.record({ publicPath: '/_client/' }),
babel({ exclude: /node_modules/ }),
json(),
resolve(),
commonjs({
namedExports: {
'node_modules/react/index.js': [
'createContext',
'createElement',
'forwardRef',
'Component',
'Fragment'
]
}
}),
replace({
'process.env.BUILD_ID': JSON.stringify(buildId),
'process.env.NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'development'
)
}),
url({
limit: 5 * 1024,
publicPath: '/_client/'
}),
compiler()
]
};
});
const dependencies = (process.env.NODE_ENV === 'development'
? Object.keys(pkg.dependencies).concat(Object.keys(pkg.devDependencies || {}))
: Object.keys(pkg.dependencies)
).concat('react-dom/server');
const server = {
external: builtinModules.concat(dependencies),
input: 'modules/server.js',
output: { file: 'server.js', format: 'cjs' },
moduleContext: {
'node_modules/react-icons/lib/esm/iconBase.js': 'global'
},
plugins: [
manifest.inject({ virtualId: 'entry-manifest' }),
babel({ exclude: /node_modules/ }),
json(),
resolve(),
commonjs(),
url({
limit: 5 * 1024,
publicPath: '/_client/',
emitFiles: false
}),
replace({
'process.env.BUILD_ID': JSON.stringify(buildId)
})
]
};
module.exports = client.concat(server);