forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
180 lines (164 loc) · 4.29 KB
/
rollup.config.js
File metadata and controls
180 lines (164 loc) · 4.29 KB
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
174
175
176
177
178
179
180
import replace from '@rollup/plugin-replace';
import { createFilter } from '@rollup/pluginutils';
import cleanup from 'rollup-plugin-cleanup';
import { version } from './package.json';
import Preprocessor from 'preprocessor';
const execSync = require('child_process').execSync;
const revision = execSync('git rev-parse --short HEAD').toString().trim();
function getBanner(config) {
return [
'/**',
' * @license',
' * PlayCanvas Engine v' + version + ' revision ' + revision + config,
' * Copyright 2011-' + new Date().getFullYear() + ' PlayCanvas Ltd. All rights reserved.',
' */'
].join('\n');
}
function spacesToTabs() {
const filter = createFilter([
'**/*.js'
], []);
return {
transform(code, id) {
if (!filter(id)) return;
return {
code: code.replace(/ /g, '\t'), // eslint-disable-line no-regex-spaces
map: { mappings: '' }
};
}
};
}
function preprocessor(options) {
const filter = createFilter([
'**/*.js'
], []);
return {
transform(code, id) {
if (!filter(id)) return;
return {
code: new Preprocessor(code).process(options),
map: { mappings: '' }
};
}
};
}
function shaderChunks(removeComments) {
const filter = createFilter([
'**/*.vert',
'**/*.frag'
], []);
return {
transform(code, id) {
if (!filter(id)) return;
// Remove carriage returns
code = code.replace(/\r/g, '');
// 4 spaces to tabs
code = code.replace(/ /g, '\t'); // eslint-disable-line no-regex-spaces
if (removeComments) {
// Remove comments
code = code.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
// Trim all whitespace from line endings
code = code.split('\n').map(line => line.trimEnd()).join('\n');
// Restore final new line
code += '\n';
// Comment removal can leave an empty line so condense 2 or more to 1
code = code.replace(/\n{2,}/g, '\n');
}
return {
code: `export default ${JSON.stringify(code)};`,
map: { mappings: '' }
};
}
};
}
export default [{
input: 'src/index.js',
output: {
banner: getBanner(''),
file: 'build/playcanvas.js',
format: 'umd',
indent: '\t',
name: 'pc'
},
plugins: [
preprocessor({
PROFILER: false,
DEBUG: false,
RELEASE: true
}),
shaderChunks(true),
replace({
__REVISION__: revision,
__CURRENT_SDK_VERSION__: version
}),
cleanup({
comments: 'some'
}),
spacesToTabs()
]
}, {
input: 'src/index.js',
output: {
banner: getBanner(' (DEBUG PROFILER)'),
file: 'build/playcanvas.dbg.js',
format: 'umd',
indent: '\t',
name: 'pc'
},
plugins: [
preprocessor({
PROFILER: true,
DEBUG: true,
RELEASE: false
}),
shaderChunks(false),
replace({
__REVISION__: revision,
__CURRENT_SDK_VERSION__: version
}),
cleanup({
comments: 'some'
}),
spacesToTabs()
]
}, {
input: 'src/index.js',
output: {
banner: getBanner(' (PROFILER)'),
file: 'build/playcanvas.prf.js',
format: 'umd',
indent: '\t',
name: 'pc'
},
plugins: [
preprocessor({
PROFILER: true,
DEBUG: false,
RELEASE: false
}),
shaderChunks(false),
replace({
__REVISION__: revision,
__CURRENT_SDK_VERSION__: version
}),
cleanup({
comments: 'some'
}),
spacesToTabs()
]
}, {
input: 'extras/index.js',
output: {
banner: getBanner(''),
file: 'build/playcanvas-extras.js',
format: 'umd',
indent: '\t',
name: 'pcx'
},
plugins: [
cleanup({
comments: 'some'
}),
spacesToTabs()
]
}];