-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
142 lines (136 loc) · 3.54 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import typescript from 'rollup-plugin-typescript2';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import { visualizer } from 'rollup-plugin-visualizer';
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import json from '@rollup/plugin-json';
import path from 'path';
import pkg from './package.json';
const isProd = process.env.NODE_ENV === 'production';
const visualizeSpace = process.env.VISUALIZE_SPACE === 'true';
const prodExtensions = ['.js', '.ts'];
const demoExtensions = [...prodExtensions, '.jsx', '.tsx'];
export const getCommonPlugins = (isUMD, extensions, babelPlugins = [], workerLoadPath) => [
alias({
entries: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom/test-utils', replacement: 'preact/test-utils' },
{ find: 'react-dom', replacement: 'preact/compat' },
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' },
],
}),
json(),
resolve({
extensions,
preventAssignment: true,
}),
replace({
'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
preventAssignment: true,
}),
commonjs({
include: /node_modules/,
}),
webWorkerLoader({
targetPlatform: 'browser',
inline: isProd && isUMD,
loadPath: workerLoadPath,
}),
typescript({
check: false,
typescript: require('typescript'),
cacheRoot: path.resolve(__dirname, '.rts2_cache'),
}),
babel({
extensions,
exclude: /node_modules/,
babelHelpers: 'runtime',
presets: ['@babel/preset-env', '@babel/preset-typescript'],
plugins: ['@babel/plugin-transform-runtime', ...babelPlugins, 'macros'],
}),
];
let config;
if (isProd) {
config = [
{
input: 'src/index.ts',
output: [
{
file: 'es/index.js',
format: 'es',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src',
},
],
external: Object.keys(pkg.dependencies),
plugins: [
...getCommonPlugins(false, prodExtensions, [], ''),
visualizeSpace &&
visualizer({
open: true,
template: 'treemap',
}),
],
},
{
input: 'src/index.ts',
output: [
{
file: `umd/index.js`,
format: 'umd',
name: 'paramVis',
plugins: [terser()],
},
],
plugins: [
...getCommonPlugins(true, prodExtensions, [], ''),
visualizeSpace &&
visualizer({
open: true,
template: 'treemap',
}),
],
},
];
} else {
config = [
{
input: 'demo/index.tsx',
output: {
dir: `demo/dist/`,
format: 'umd',
sourcemap: true,
},
plugins: [
...getCommonPlugins(
true,
demoExtensions,
[
[
'@babel/plugin-transform-react-jsx',
{
pragma: 'h',
pragmaFrag: 'Fragment',
},
],
],
'/dist',
),
serve({
open: true,
contentBase: ['', 'demo'],
port: 9000,
}),
livereload({ watch: ['src', 'demo'], port: 9000 }),
],
},
];
}
export default config;