forked from stwflyfox/unpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
97 lines (89 loc) · 2.67 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
require('dotenv').config();
const path = require('path');
const builtinModules = require('module').builtinModules;
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 env = process.env.BUILD_ENV || 'development';
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'
}
},
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.NODE_ENV': JSON.stringify(env)
}),
url({
limit: 5 * 1024,
publicPath: '/_client/'
}),
compiler(
env !== 'production' ? { formatting: 'PRETTY_PRINT' } : undefined
)
]
};
});
const dependencies = (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: path.resolve(__dirname, 'modules/server.js'),
output: { file: 'server.js', format: 'cjs' },
plugins: [
manifest.inject({ virtualId: 'entry-manifest' }),
babel({ exclude: /node_modules/ }),
json(),
resolve(),
commonjs(),
url({
limit: 5 * 1024,
publicPath: '/_client/',
emitFiles: false
}),
replace({
'process.env.CLOUDFLARE_EMAIL': JSON.stringify(
process.env.CLOUDFLARE_EMAIL
),
'process.env.CLOUDFLARE_KEY': JSON.stringify(process.env.CLOUDFLARE_KEY),
'process.env.NPM_REGISTRY_URL': JSON.stringify(
process.env.NPM_REGISTRY_URL
),
'process.env.ORIGIN': JSON.stringify(process.env.ORIGIN)
})
]
};
module.exports = client.concat(server);