forked from playcanvas/supersplat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
104 lines (97 loc) · 3.08 KB
/
rollup.config.mjs
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
import path from 'path';
import copyAndWatch from './copy-and-watch.mjs';
import alias from '@rollup/plugin-alias';
import image from '@rollup/plugin-image';
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import strip from '@rollup/plugin-strip';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import sass from 'rollup-plugin-sass';
// import { visualizer } from 'rollup-plugin-visualizer';
// prod is release build
if (process.env.BUILD_TYPE === 'prod') {
process.env.BUILD_TYPE = 'release';
}
// debug, profile, release
const HREF = process.env.BASE_HREF || '';
const BUILD_TYPE = process.env.BUILD_TYPE || 'release';
const ENGINE_DIR = process.env.ENGINE_PATH || './node_modules/playcanvas';
const EXTRAS_DIR = path.resolve(ENGINE_DIR, 'build', 'playcanvas-extras.mjs');
const PCUI_DIR = path.resolve(process.env.PCUI_PATH || 'node_modules/@playcanvas/pcui');
const ENGINE_NAME = BUILD_TYPE === 'debug' ? 'playcanvas.dbg.mjs' : 'playcanvas.mjs';
const ENGINE_PATH = path.resolve(ENGINE_DIR, 'build', ENGINE_NAME);
const aliasEntries = {
playcanvas: ENGINE_PATH,
'playcanvas-extras': EXTRAS_DIR,
'pcui': PCUI_DIR
};
const tsCompilerOptions = {
baseUrl: '.',
paths: {
playcanvas: [ENGINE_DIR],
'playcanvas-extras': [EXTRAS_DIR],
'pcui': [PCUI_DIR]
}
};
const pipeline = (input) => {
return {
input: input,
output: {
dir: 'dist',
format: 'esm',
sourcemap: true
},
plugins: [
copyAndWatch({
targets: [
{
src: 'src/index.html',
transform: (contents, filename) => {
return contents.toString().replace('__BASE_HREF__', HREF);
}
},
{src: 'static/lib/draco_decoder.wasm', dest: 'static/lib'},
{src: 'static/env/VertebraeHDRI_v1_512.png', dest: 'static/env'}
]
}),
alias({entries: aliasEntries}),
resolve(),
image({dom: true}),
sass({
insert: false,
output: 'dist/style.css',
outputStyle: 'compressed'
}),
json(),
typescript({
compilerOptions: tsCompilerOptions
}),
BUILD_TYPE === 'release' &&
strip({
include: ['**/*.ts'],
functions: ['Debug.exec']
}),
BUILD_TYPE !== 'debug' && terser()
// visualizer()
],
treeshake: 'smallest',
cache: false
};
};
export default [
{
input: 'static/lib/draco_decoder.js',
output: {
file: 'dist/static/lib/draco_decoder.js'
},
plugins: [
terser({
mangle: {
reserved: ['DracoDecoderModule']
}
})
]
},
pipeline('src/index.ts'),
];