-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
460 lines (438 loc) · 14.8 KB
/
rollup.config.js
File metadata and controls
460 lines (438 loc) · 14.8 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
import path from 'path';
import { fileURLToPath } from 'url';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import analyzer from 'rollup-plugin-analyzer';
import bundleSize from 'rollup-plugin-bundle-size';
import { visualizer } from 'rollup-plugin-visualizer';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Environment detection
const isProduction = process.env.NODE_ENV === 'production';
const shouldAnalyze = process.env.ANALYZE === 'true';
// Bundle size limits (in bytes) - DEPRECATED: Now using package.json bundlesize
// const BUNDLE_SIZE_LIMITS = {
// umd: 51200, // 50KB
// es: 40960, // 40KB
// minimal: 20480 // 20KB for minimal build
// };
// Base plugins used by all builds
const basePlugins = [
resolve({
browser: true,
preferBuiltins: false
}),
commonjs()
];
// 3D plugins (Three.js handles shaders natively, no plugin needed)
const threeDPlugins = [
...basePlugins
];
// Production plugins
const productionPlugins = [
...basePlugins,
terser({
compress: {
drop_console: false,
pure_funcs: ['console.log'],
drop_debugger: true,
passes: 2,
unsafe_arrows: true,
unsafe_methods: true,
unsafe_proto: true,
unsafe_regexp: true
},
mangle: {
properties: false
},
format: {
comments: false
}
})
];
// Development plugins
const developmentPlugins = [
...basePlugins
];
// Analysis plugins
const analysisPlugins = shouldAnalyze ? [
analyzer({
summaryOnly: true,
limit: 10
}),
bundleSize(),
visualizer({
filename: 'dist/bundle-analysis.html',
open: true,
gzipSize: true,
brotliSize: true
})
] : [];
// Minimal-build import redirects (gesture pruning + audio stripping)
// Swaps heavy modules for lightweight stubs ONLY in the minimal build.
// Uses resolved absolute paths so './index.js' from within gestures/ is caught.
function minimalRedirects() {
const coreDir = path.resolve(__dirname, 'src/core');
const srcDir = path.resolve(__dirname, 'src');
// Map absolute source paths → absolute replacement paths
const absoluteRedirects = {
// Gesture pruning: 134 → ~25 gestures
[path.resolve(coreDir, 'gestures/index.js')]:
path.resolve(coreDir, 'gestures/index-minimal.js'),
// Audio stripping: no-op stubs
[path.resolve(coreDir, 'audio/rhythm.js')]:
path.resolve(coreDir, '_stubs/rhythm.stub.js'),
[path.resolve(coreDir, 'audio/rhythmIntegration.js')]:
path.resolve(coreDir, '_stubs/rhythmIntegration.stub.js'),
[path.resolve(coreDir, 'morpher/AudioDeformer.js')]:
path.resolve(coreDir, '_stubs/AudioDeformer.stub.js'),
[path.resolve(coreDir, 'morpher/MusicDetector.js')]:
path.resolve(coreDir, '_stubs/MusicDetector.stub.js'),
// Positioning: element targeting + full positioning system
[path.resolve(coreDir, 'positioning/index.js')]:
path.resolve(coreDir, '_stubs/positioning.stub.js'),
[path.resolve(coreDir, 'positioning/elementTargeting/index.js')]:
path.resolve(coreDir, '_stubs/elementTargeting.stub.js'),
// Debugger
[path.resolve(srcDir, 'utils/debugger.js')]:
path.resolve(coreDir, '_stubs/debugger.stub.js'),
// Musical duration (audio-tempo gesture timing)
[path.resolve(coreDir, 'audio/MusicalDuration.js')]:
path.resolve(coreDir, '_stubs/MusicalDuration.stub.js'),
// Gesture orchestration
[path.resolve(coreDir, 'GestureCompatibility.js')]:
path.resolve(coreDir, '_stubs/GestureCompatibility.stub.js'),
[path.resolve(coreDir, 'GestureCompositor.js')]:
path.resolve(coreDir, '_stubs/GestureCompositor.stub.js'),
// Sleep manager
[path.resolve(coreDir, 'renderer/SleepManager.js')]:
path.resolve(coreDir, '_stubs/SleepManager.stub.js'),
// Effects registry (zen-vortex, sleeping, recording-glow, etc.)
[path.resolve(coreDir, 'effects/index.js')]:
path.resolve(coreDir, '_stubs/effects.stub.js'),
};
return {
name: 'minimal-redirects',
resolveId(source, importer) {
if (!importer || !source.startsWith('.')) return null;
// Resolve the import to an absolute path
const resolved = path.resolve(path.dirname(importer), source);
// Check with and without .js extension
const candidate = resolved.endsWith('.js') ? resolved : `${resolved }.js`;
if (absoluteRedirects[candidate]) {
return absoluteRedirects[candidate];
}
return null;
}
};
}
// Build configurations
const builds = [];
// Full-featured builds (ES Module + UMD)
builds.push({
input: 'src/index.js',
output: [
{
// ES Module for NPM consumers (bundlers like Webpack, Vite, etc.)
file: 'dist/mascot.js',
format: 'es',
sourcemap: true,
banner: `/*! Emotive Engine v${process.env.npm_package_version || '3.4.0'} | MIT License */`
},
{
// UMD for CDN/browser usage (includes all features)
file: 'dist/emotive-mascot.umd.js',
format: 'umd',
name: 'EmotiveMascot',
exports: 'named',
sourcemap: true,
banner: `/*! Emotive Engine v${process.env.npm_package_version || '3.4.0'} | MIT License */`
}
],
plugins: [
...(isProduction ? productionPlugins : developmentPlugins),
...analysisPlugins
],
treeshake: {
moduleSideEffects: false // Enable aggressive tree-shaking
}
});
// Lean build (ultra-optimized for homepage/marketing sites)
// Removes: rhythm sync, undertone saturation, accessibility, performance monitoring
// Smaller bundle with core emotions, gestures, and particle system
builds.push({
input: 'src/lean.js',
output: [
{
file: 'dist/emotive-mascot.lean.js',
format: 'es',
sourcemap: true,
banner: `/*! Emotive Engine Lean v${process.env.npm_package_version || '3.4.0'} | MIT License */`
},
{
file: 'dist/emotive-mascot.lean.umd.js',
format: 'umd',
name: 'EmotiveMascotLean', // Different name for lean build
exports: 'named',
sourcemap: true,
banner: `/*! Emotive Engine Lean v${process.env.npm_package_version || '3.4.0'} | MIT License */`
}
],
plugins: [
...basePlugins,
terser({
compress: {
drop_console: true, // Remove console.* in production
drop_debugger: true,
passes: 3, // More aggressive optimization
pure_funcs: ['console.log', 'console.warn', 'console.info'],
unsafe_arrows: true,
unsafe_methods: true,
unsafe_proto: true,
unsafe_regexp: true,
dead_code: true,
evaluate: true,
inline: 3
},
mangle: {
properties: {
regex: /^_/ // Mangle private properties starting with _
}
},
format: {
comments: false
}
})
],
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
unknownGlobalSideEffects: false
}
});
// Minimal build (ultra-light loading screen — no audio, plugins, or managers)
// Only includes: emotions, 2D gestures, shape morphing, particles
// Designed as a loading screen that hands off to the full 3D mascot
// Uses minimalRedirects() to swap heavy gesture index + audio modules for stubs
builds.push({
input: 'src/minimal.js',
output: [
{
file: 'dist/emotive-mascot.minimal.js',
format: 'es',
sourcemap: true,
banner: `/*! Emotive Engine Minimal v${process.env.npm_package_version || '3.4.0'} | MIT License */`
},
{
file: 'dist/emotive-mascot.minimal.umd.js',
format: 'umd',
name: 'EmotiveMascotMinimal',
exports: 'named',
sourcemap: true,
banner: `/*! Emotive Engine Minimal v${process.env.npm_package_version || '3.4.0'} | MIT License */`
}
],
plugins: [
minimalRedirects(),
...basePlugins,
terser({
compress: {
drop_console: true,
drop_debugger: true,
passes: 3,
pure_funcs: ['console.log', 'console.warn', 'console.info'],
unsafe_arrows: true,
unsafe_methods: true,
unsafe_proto: true,
unsafe_regexp: true,
dead_code: true,
evaluate: true,
inline: 3
},
mangle: {
properties: {
regex: /^_/
}
},
format: {
comments: false
}
})
],
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
unknownGlobalSideEffects: false
}
});
// 3D build (WebGL variant with procedural geometries)
// Three.js is a peer dependency - not bundled (for npm consumers with bundlers)
builds.push({
input: 'src/3d/index.js',
output: [
{
// ES Module - three.js external (for bundlers like Webpack, Vite)
file: 'dist/emotive-mascot-3d.js',
format: 'es',
sourcemap: true,
inlineDynamicImports: true,
banner: `/*! Emotive Engine 3D v${process.env.npm_package_version || '3.4.0'} | MIT License */`
},
{
// UMD - three.js external (expects global THREE)
file: 'dist/emotive-mascot-3d.umd.js',
format: 'umd',
name: 'EmotiveMascot3D',
exports: 'named',
sourcemap: true,
inlineDynamicImports: true,
banner: `/*! Emotive Engine 3D v${process.env.npm_package_version || '3.4.0'} | MIT License */`,
globals: {
three: 'THREE'
}
}
],
external: ['three'],
plugins: [
...threeDPlugins,
...(isProduction ? [terser({
compress: {
drop_console: false,
pure_funcs: ['console.log'],
drop_debugger: true,
passes: 2
},
mangle: {
properties: false
},
format: {
comments: false
}
})] : [])
],
treeshake: {
moduleSideEffects: false
}
});
// 3D build BUNDLED (for static HTML examples - includes Three.js)
builds.push({
input: 'src/3d/index.js',
output: [
{
// ES Module with Three.js bundled - for static HTML demos
file: 'dist/emotive-mascot-3d.bundled.js',
format: 'es',
sourcemap: true,
inlineDynamicImports: true,
banner: `/*! Emotive Engine 3D (bundled) v${process.env.npm_package_version || '3.4.0'} | MIT License */`
}
],
// No external - bundle everything including Three.js
plugins: [
...threeDPlugins,
...(isProduction ? [terser({
compress: {
drop_console: false,
pure_funcs: ['console.log'],
drop_debugger: true,
passes: 2
},
mangle: {
properties: false
},
format: {
comments: false
}
})] : [])
],
treeshake: {
moduleSideEffects: false
}
});
// 3D build WITH ELEMENTALS (full elemental system — 151+ gestures, instanced materials)
// Three.js is a peer dependency - not bundled (for npm consumers with bundlers)
builds.push({
input: 'src/3d/index-with-elementals.js',
output: [
{
// ES Module - three.js external (for bundlers like Webpack, Vite)
file: 'dist/emotive-mascot-3d-elementals.js',
format: 'es',
sourcemap: true,
inlineDynamicImports: true,
banner: `/*! Emotive Engine 3D + Elementals v${process.env.npm_package_version || '3.4.0'} | MIT License */`
},
{
// UMD - three.js external (expects global THREE)
file: 'dist/emotive-mascot-3d-elementals.umd.js',
format: 'umd',
name: 'EmotiveMascot3D',
exports: 'named',
sourcemap: true,
inlineDynamicImports: true,
banner: `/*! Emotive Engine 3D + Elementals v${process.env.npm_package_version || '3.4.0'} | MIT License */`,
globals: {
three: 'THREE'
}
}
],
external: ['three'],
plugins: [
...threeDPlugins,
...(isProduction ? [terser({
compress: {
drop_console: false,
pure_funcs: ['console.log'],
drop_debugger: true,
passes: 2
},
mangle: {
properties: false
},
format: {
comments: false
}
})] : [])
],
treeshake: {
moduleSideEffects: true // Preserve side-effect imports (element registrations + gesture registration)
}
});
// 3D build WITH ELEMENTALS BUNDLED (includes Three.js - for static HTML examples)
builds.push({
input: 'src/3d/index-with-elementals.js',
output: [
{
// ES Module with Three.js bundled - for static HTML demos
file: 'dist/emotive-mascot-3d-elementals.bundled.js',
format: 'es',
sourcemap: true,
inlineDynamicImports: true,
banner: `/*! Emotive Engine 3D + Elementals (bundled) v${process.env.npm_package_version || '3.4.0'} | MIT License */`
}
],
// No external - bundle everything including Three.js
plugins: [
...threeDPlugins,
...(isProduction ? [terser({
compress: {
drop_console: false,
pure_funcs: ['console.log'],
drop_debugger: true,
passes: 2
},
mangle: {
properties: false
},
format: {
comments: false
}
})] : [])
],
treeshake: {
moduleSideEffects: true // Preserve side-effect imports (element registrations + gesture registration)
}
});
export default builds;