forked from LiveDuo/destack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
100 lines (97 loc) · 2.41 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
import esbuild from 'rollup-plugin-esbuild'
import resolve from '@rollup/plugin-node-resolve'
import postcss from 'rollup-plugin-postcss'
import commonjs from '@rollup/plugin-commonjs'
import replace from 'rollup-plugin-re'
import image from '@rollup/plugin-image'
import tailwindcss from 'tailwindcss'
const browserConfig = {
input: 'client/index.tsx',
output: [
{
dir: 'build/browser',
format: 'cjs',
},
],
onwarn(warning, rollupWarn) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
rollupWarn(warning)
}
},
external: ['next', 'react', 'react-dom'],
plugins: [
image({}),
postcss({
extract: true,
plugins: [tailwindcss('./tailwind.config.js')],
}),
commonjs({
requireReturnsDefault: false,
defaultIsModuleExports: true,
}),
resolve({ preferBuiltins: true }),
esbuild({
include: /\.[jt]sx?$/,
exclude: /node_modules/,
sourceMap: process.env.NODE_ENV !== 'production',
minify: process.env.NODE_ENV === 'production',
target: 'es2017',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
// Like @rollup/plugin-replace
define: {
__VERSION__: '"x.y.z"',
},
tsconfig: 'tsconfig.json',
loaders: {
'.json': 'json',
'.js': 'jsx',
},
}),
],
}
const nodeConfig = {
input: 'server/index.ts',
output: [
{
dir: 'build/server/',
format: 'cjs',
},
],
plugins: [
resolve({ preferBuiltins: true }),
replace({
// https://github.com/rollup/rollup-plugin-commonjs/issues/166
// Note: Replace before commonjs
patterns: [
{
match: /formidable(\/|\\)lib/,
test: 'if (global.GENTLY) require = GENTLY.hijack(require);',
replace: '',
},
],
}),
commonjs({
requireReturnsDefault: false,
defaultIsModuleExports: true,
}),
esbuild({
include: /\.[jt]sx?$/,
exclude: /node_modules/,
sourceMap: process.env.NODE_ENV !== 'production', // default
minify: process.env.NODE_ENV === 'production',
target: 'node10',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
define: {
__VERSION__: '"x.y.z"',
},
tsconfig: 'tsconfig.json',
loaders: {
'.json': 'json',
'.js': 'jsx',
},
}),
],
}
export default [browserConfig, nodeConfig]