-
Notifications
You must be signed in to change notification settings - Fork 549
Expand file tree
/
Copy pathvite.worker.config.ts
More file actions
64 lines (62 loc) · 1.63 KB
/
Copy pathvite.worker.config.ts
File metadata and controls
64 lines (62 loc) · 1.63 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
import { defineConfig } from 'vite';
import path from 'path';
// Minimal document/DOM shim for PixiJS in Web Worker context.
// PixiJS pipes (DOMPipe, AccessibilitySystem) access `document` in their
// constructors at module evaluation time, before WebWorkerAdapter can be set.
// This shim provides no-op DOM elements so those constructors don't crash.
const workerDomShim = `
(function() {
if (typeof document !== 'undefined') return;
var noop = function() {};
var noopEl = {
style: {},
appendChild: noop,
removeChild: noop,
remove: noop,
contains: function() { return false; },
setAttribute: noop,
getAttribute: noop,
classList: { add: noop, remove: noop, toggle: noop, contains: function() { return false; } },
addEventListener: noop,
removeEventListener: noop,
};
self.document = {
createElement: function() {
return Object.create(noopEl);
},
createElementNS: function() {
return Object.create(noopEl);
},
body: Object.create(noopEl),
head: Object.create(noopEl),
addEventListener: noop,
removeEventListener: noop,
baseURI: '',
};
if (typeof navigator === 'undefined') {
self.navigator = { userAgent: '', maxTouchPoints: 0 };
}
if (typeof window === 'undefined') {
self.window = self;
}
})();
`;
export default defineConfig({
build: {
outDir: path.resolve(__dirname, 'dist/workers/lib'),
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, 'src/ts/workers/pixi-worker-entry.ts'),
name: 'pixi',
formats: ['iife'],
fileName: () => 'pixi.min.js',
},
minify: 'esbuild',
rollupOptions: {
output: {
inlineDynamicImports: true,
intro: workerDomShim,
},
},
},
});