-
Notifications
You must be signed in to change notification settings - Fork 7
/
rollup.config.js
173 lines (163 loc) · 4.31 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import image from '@rollup/plugin-image';
import json from '@rollup/plugin-json';
import { string } from "rollup-plugin-string";
import terser from '@rollup/plugin-terser';
import postcss from 'rollup-plugin-postcss';
import header from "postcss-header";
import cssnano from "cssnano";
import copy from 'rollup-plugin-copy';
import glslify from 'rollup-plugin-glslify';
import pkg from './package.json';
const PLUGINS_COMMON = [
resolve(), // so Rollup can find libraries
commonjs(), // so Rollup can convert libraries to an ES modules
image({
include: [
"**/assets/**.png",
"**/assets/brushes/**.png",
"**/assets/templates/**.png"
],
exclude: []
}),
string({
include: [
"**/assets/*.svg",
"**/assets/*.csv",
"**/assets/brushes/*.csv",
"**/assets/tools/*.svg",
],
exclude: []
}),
json({
compact: true,
include: [
"**/assets/structures/*.json",
],
exclude: []
}),
glslify({
compress: true,
include: [
"**/shaders/*.glsl",
],
exclude: []
})
];
let SGJS_OUTPUTS = [
{
// browser-friendly UMD build
name: 'SandGameJS',
file: 'dist/sand-game-js.umd.js',
banner: pkg.copyright,
format: 'umd',
sourcemap: true,
}
]
let SGJS_DEV_MODULE_OUTPUTS = [
{
// browser-friendly UMD build
name: 'SandGameJS_ModuleDev',
file: 'dist/sand-game-js_module-dev.umd.js',
banner: pkg.copyright,
format: 'umd',
sourcemap: true,
}
]
const devBuild = process.env.npm_lifecycle_script.endsWith('-w');
if (devBuild) {
console.log('DEV build');
} else {
console.log('PROD build');
PLUGINS_COMMON.push(copy({
targets: [
{
src: 'tools/palette-designer/tool-palette-designer.umd.js',
dest: 'dist'
},
{
src: 'tools/palette-designer/tool-palette-designer.css',
dest: 'dist'
},
{
src: 'tools/texture-designer/tool-texture-designer.umd.js',
dest: 'dist'
},
{
src: 'tools/texture-designer/tool-texture-designer.css',
dest: 'dist'
},
{
src: 'tools/scenario-ide/tool-scenario-ide.umd.js',
dest: 'dist'
},
{
src: 'tools/scenario-ide/tool-scenario-ide.css',
dest: 'dist'
}
]
}));
const PLUGINS_MIN = [
terser({
sourceMap: true,
format: {
preamble: pkg.copyright,
comments: false
}
})
];
SGJS_OUTPUTS.push({
// browser-friendly UMD build, MINIMIZED
name: 'SandGameJS',
file: 'dist/sand-game-js.umd.min.js',
format: 'umd',
sourcemap: true,
plugins: PLUGINS_MIN
});
SGJS_DEV_MODULE_OUTPUTS.push({
// browser-friendly UMD build, MINIMIZED
name: 'SandGameJS_ModuleDev',
file: 'dist/sand-game-js_module-dev.umd.min.js',
format: 'umd',
sourcemap: true,
plugins: PLUGINS_MIN
});
}
export default [
{
input: 'src/main.js',
plugins: PLUGINS_COMMON,
output: SGJS_OUTPUTS
},
{
input: 'src/style.css',
plugins: [
postcss({
extract: true,
modules: false,
sourceMap: true,
plugins: [
cssnano({
preset: 'default',
}),
header({
header: pkg.copyright,
})
],
}),
],
output: {
file: 'dist/sand-game-js.css',
},
onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT') return;
warn(warning);
}
},
{
input: 'src/module-dev.js',
plugins: PLUGINS_COMMON,
output: SGJS_DEV_MODULE_OUTPUTS
},
];