forked from playcanvas/model-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
94 lines (87 loc) · 2.87 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
// official rollup plugins
import alias from '@rollup/plugin-alias';
import image from '@rollup/plugin-image';
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import path from 'path';
import resolve from "@rollup/plugin-node-resolve";
import replace from '@rollup/plugin-replace';
import sass from 'rollup-plugin-sass';
import terser from '@rollup/plugin-terser';
import typescript from "@rollup/plugin-typescript";
// custom plugins
import { copyAndWatch } from "./plugins/copy-and-watch.mjs";
// debug, profile, release
const BUILD_TYPE = process.env.BUILD_TYPE || 'release';
const ENGINE_DIR = process.env.ENGINE_PATH || 'node_modules/playcanvas';
const ENGINE_NAME = (BUILD_TYPE === 'debug') ? 'playcanvas.dbg/src/index.js' : 'playcanvas/src/index.js';
const ENGINE_PATH = path.resolve(ENGINE_DIR, 'build', ENGINE_NAME);
const PCUI_DIR = path.resolve(process.env.PCUI_PATH || 'node_modules/@playcanvas/pcui');
const BLUE_OUT = '\x1b[34m';
const BOLD_OUT = `\x1b[1m`;
const REGULAR_OUT = `\x1b[22m`;
const RESET_OUT = `\x1b[0m`;
const title = [
`Building PlayCanvas Model Viewer`,
`type ${BOLD_OUT}${BUILD_TYPE}${REGULAR_OUT}`,
`engine ${BOLD_OUT}${ENGINE_DIR}${REGULAR_OUT}`,
`pcui ${BOLD_OUT}${PCUI_DIR}${REGULAR_OUT}`
].map(l => `${BLUE_OUT}${l}`).join(`\n`);
console.log(`${BLUE_OUT}${title}${RESET_OUT}\n`);
const TARGETS = [
{
src: 'src/index.html',
transform: (contents) => {
return contents.toString()
.replace('__BASE_HREF__', process.env.BASE_HREF || '')
.replace('__');
}
},
{ src: 'src/manifest.json' },
{ src: 'src/fonts.css' },
{ src: 'static/' }
];
export default {
input: 'src/index.tsx',
output: {
dir: 'dist',
format: 'esm',
sourcemap: true
},
treeshake: 'smallest',
plugins: [
copyAndWatch(TARGETS),
replace({
values: {
// NOTE: this is required for react (??) - see https://github.com/rollup/rollup/issues/487#issuecomment-177596512
'process.env.NODE_ENV': JSON.stringify(BUILD_TYPE === 'release' ? 'production' : 'development')
},
preventAssignment: true
}),
sass({
insert: false,
output: 'dist/style.css',
outputStyle: 'compressed'
}),
image({ dom: true }),
alias({
entries: {
'playcanvas': ENGINE_PATH,
'@playcanvas/pcui': PCUI_DIR
}
}),
commonjs(),
resolve(),
typescript({
compilerOptions: {
baseUrl: '.',
paths: {
'playcanvas': [ENGINE_DIR],
'@playcanvas/pcui': [PCUI_DIR]
}
}
}),
json(),
(BUILD_TYPE !== 'debug') && terser()
]
};