forked from webgpu/webgpu-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
143 lines (135 loc) · 3.7 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
143
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import fs from 'fs';
import process from 'process';
import postcss from 'rollup-plugin-postcss';
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const isWatch = process.env.ROLLUP_WATCH;
async function getServeAndLiveloadPlugins() {
console.log('loading server and liveReload plugins');
// we can't always load these as apparently they start processes and so
// node never exits.
const { default: livereload } = await import('rollup-plugin-livereload');
const { default: serve } = await import('rollup-plugin-serve');
return [
serve({
open: true,
openPage: process.env.START_PATH || '/examples/',
verbose: true,
contentBase: [''],
host: 'localhost',
port: 3000,
}),
livereload({ watch: 'dist' }),
];
}
const plugins = [
resolve({
browser: true,
}),
typescript({ tsconfig: './tsconfig.json' }),
];
const commonConfig = {
// This is a hack to workaround a warning that should be fixed
onwarn(warning, warn) {
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}
warn(warning);
},
plugins: [
resolve({
browser: true,
}),
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify('development'),
},
}),
commonjs({
include: /node_modules/,
requireReturnsDefault: 'auto', // <---- this solves default issue
}),
typescript({
tsconfig: './tsconfig.json',
sourceRoot: '/src',
}),
postcss({
minimize: true,
sourceMap: true,
}),
...(isWatch ? await getServeAndLiveloadPlugins() : []),
],
};
const commonUIConfig = {
input: 'src/ui/index.ts',
...commonConfig,
};
async function getConfig() {
return [
{
input: 'src/capture/index.ts',
output: [
{
file: 'dist/capture.js',
format: 'esm',
sourcemap: true,
},
],
plugins,
},
{
input: 'src/replay/index.ts',
output: [
{
file: 'dist/replay.js',
format: 'esm',
sourcemap: true,
},
],
plugins,
},
{
...commonUIConfig,
output: [
{
file: packageJson.module,
format: 'esm',
sourcemap: true,
},
],
},
{
...commonUIConfig,
output: [
{
file: 'dist/webgpu-debugger.umd.js',
format: 'umd',
sourcemap: true,
name: 'webgpuDebugger',
},
],
},
{
...commonConfig,
input: 'src/test/main.ts',
output: [
{
file: 'out/main.js',
format: 'esm',
sourcemap: true,
},
],
},
//{
// input: "dist/esm/types/index.d.ts",
// output: [{ file: "dist/index.d.ts", format: "esm" }],
// external: [/\.css$/],
// plugins: [dts()],
//},
];
}
export default getConfig();