-
Notifications
You must be signed in to change notification settings - Fork 15
/
rollup.config.mjs
107 lines (95 loc) · 2.71 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
105
106
107
import path from 'path';
// 1st party plugins
import alias from '@rollup/plugin-alias';
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
// 3rd party plugins
import jscc from 'rollup-plugin-jscc';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import postcss from 'rollup-plugin-postcss';
const PCUI_DIR = process.env.PCUI_PATH || 'node_modules/@playcanvas/pcui';
const PCUI_PATH = path.resolve(PCUI_DIR, 'react');
// define supported module overrides
const aliasEntries = {
'pcui': PCUI_PATH
};
const umd = {
input: 'src/index.js',
output: {
file: 'dist/pcui-graph.js',
format: 'umd',
name: 'pcuiGraph',
globals: {
'@playcanvas/observer': 'observer',
'@playcanvas/pcui': 'pcui'
}
},
external: ['@playcanvas/observer', '@playcanvas/pcui'],
plugins: [
jscc({
values: { _STRIP_SCSS: process.env.STRIP_SCSS }
}),
postcss({
minimize: false,
extensions: ['.css', '.scss']
}),
alias({ entries: aliasEntries }),
commonjs({ transformMixedEsModules: true }),
globals(),
builtins(),
babel({ babelHelpers: 'bundled' }),
resolve(),
process.env.NODE_ENV === 'production' && terser()
]
};
const module = {
input: 'src/index.js',
output: {
file: 'dist/pcui-graph.mjs',
format: 'module'
},
external: ['@playcanvas/observer', '@playcanvas/pcui'],
plugins: [
jscc({
values: { _STRIP_SCSS: process.env.STRIP_SCSS }
}),
alias({ entries: aliasEntries }),
commonjs({ transformMixedEsModules: true }),
globals(),
builtins(),
babel({ babelHelpers: 'bundled' }),
postcss({
minimize: false,
extensions: ['.css', '.scss']
}),
resolve(),
process.env.NODE_ENV === 'production' && terser()
]
};
const styles = {
input: 'src/styles/index.js',
output: {
file: 'styles/dist/index.mjs',
format: 'esm'
},
plugins: [
resolve(),
postcss({
minimize: false,
extensions: ['.css', '.scss']
})
]
};
let targets;
if (process.env.target) {
switch (process.env.target.toLowerCase()) {
case "umd": targets = [umd]; break;
case "module": targets = [module]; break;
case "styles": targets = [styles]; break;
case "all": targets = [umd, module, styles]; break;
}
}
export default targets;