forked from flipcomputing/flock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mjs
More file actions
284 lines (276 loc) · 8.52 KB
/
vite.config.mjs
File metadata and controls
284 lines (276 loc) · 8.52 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
import { VitePWA } from 'vite-plugin-pwa'
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { copyFileSync, readdirSync } from 'fs';
import { resolve } from 'path';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
import { writeFileSync } from 'fs';
// Determine if we are in production mode
const isProduction = process.env.NODE_ENV === 'production';
const BASE_URL = process.env.VITE_BASE_URL || '/';
export default {
plugins: [
cssInjectedByJsPlugin(),
viteStaticCopy({
targets: [
{
src: 'models/*.{glb,gltf}',
dest: 'models'
},
{
src: 'animations/*.{glb,gltf}',
dest: 'animations'
},
{
src: 'sounds/*.{ogg,mp3,aac,wav}',
dest: 'sounds'
},
{
src: 'images/*.*',
dest: 'images'
},
{
src: 'examples/*.json',
dest: 'examples'
},
{
src: 'textures/*.png',
dest: 'textures'
},
{
src: 'fonts/*.{json,woff2}',
dest: 'fonts'
},
{
src: 'node_modules/blockly/media/*',
dest: 'blockly/media',
},
{
src: 'images/dropdown-arrow.svg',
dest: 'blockly/media',
},
/*{
src: 'flock.js',
dest: ''
}*/
]
}),
VitePWA({
base: BASE_URL,
registerType: 'autoUpdate',
devOptions: {
enabled: false
},
assetsInclude: ['**/*.glb', '**/*.gltf', '**/*.ogg', '**/*.aac', '**/*.mp3', '**/*.json', '**/*.png', '**/*.woff', '**/*.woff2', '**/*.css', '**/*.svg', '**/*.wasm'],
includeAssets: ['**/*.glb', '**/*.gltf', '**/*.ogg', '**/*.aac', '**/*.mp3', '**/*.json', '**/*.png', '**/*.woff', '**/*.woff2', '**/*.css', '**/*.svg', '**/*.wasm'],
manifest: {
name: 'Flock XR - Creative coding in 3D',
short_name: 'Flock XR',
description: 'Create 3D apps with code blocks',
theme_color: '#511d91',
background_color: '#ffffff',
display: 'fullscreen',
start_url: isProduction ? BASE_URL + '?fullscreen=true' : '/',
id: isProduction ? BASE_URL + '?fullscreen=true' : '/',
scope: BASE_URL,
orientation: 'any',
categories: ['education', 'games'],
icons: [
{
src: 'images/icon_192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any maskable'
},
{
src: 'images/icon_512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
}
]
},
workbox: {
maximumFileSizeToCacheInBytes: 25000000,
globPatterns: [
'**/*.{js,css,html,ico,png,svg,glb,gltf,ogg,mp3,aac,wasm,json,woff,woff2}',
'models/**/*',
'sounds/**/*',
'images/**/*',
'examples/**/*',
'textures/**/*',
'fonts/**/*',
'blockly/media/**/*'
],
modifyURLPrefix: isProduction ? {
'': BASE_URL, // Prepend the base URL to all cached assets in production
} : {},
ignoreURLParametersMatching: [/^fullscreen$/],
additionalManifestEntries: [
{ url: isProduction ? BASE_URL + '?fullscreen=true' : '/', revision: null }
],
runtimeCaching: [
{
// Cache all static assets
urlPattern: /.*\.(glb|gltf|ogg|mp3|aac|png|jpg|jpeg|svg|wasm|json|woff|woff2|css|js|html)$/,
handler: 'CacheFirst',
options: {
cacheName: 'static-assets',
expiration: {
maxEntries: 1000,
maxAgeSeconds: 365 * 24 * 60 * 60, // Cache for 1 year
},
},
},
{
// Cache models directory
urlPattern: /\/models\/.*/,
handler: 'CacheFirst',
options: {
cacheName: 'models-cache',
expiration: {
maxEntries: 100,
maxAgeSeconds: 365 * 24 * 60 * 60,
},
},
},
{
// Cache sounds directory
urlPattern: /\/sounds\/.*/,
handler: 'CacheFirst',
options: {
cacheName: 'sounds-cache',
rangeRequests: true,
expiration: {
maxEntries: 100,
maxAgeSeconds: 365 * 24 * 60 * 60,
},
},
},
{
// Cache textures directory
urlPattern: /\/textures\/.*/,
handler: 'CacheFirst',
options: {
cacheName: 'textures-cache',
expiration: {
maxEntries: 100,
maxAgeSeconds: 365 * 24 * 60 * 60,
},
},
},
{
// Cache examples directory
urlPattern: /\/examples\/.*/,
handler: 'CacheFirst',
options: {
cacheName: 'examples-cache',
expiration: {
maxEntries: 50,
maxAgeSeconds: 365 * 24 * 60 * 60,
},
},
},
{
// Cache Blockly media files
urlPattern: /\/blockly\/media\/.*/,
handler: 'CacheFirst',
options: {
cacheName: 'blockly-media',
expiration: {
maxEntries: 50,
maxAgeSeconds: 365 * 24 * 60 * 60,
},
},
},
{
// Cache same-origin requests
urlPattern: ({ url }) => url.origin === self.location.origin,
handler: 'CacheFirst',
options: {
cacheName: 'same-origin-cache',
expiration: {
maxEntries: 200,
maxAgeSeconds: 365 * 24 * 60 * 60,
},
},
},
],
cleanupOutdatedCaches: true, // Remove old cache versions
},
}),
{
name: 'create-flock-proxy',
writeBundle(options, bundle) {
let hashedFileName;
for (const fileName in bundle) {
if (fileName.startsWith('assets/index-') && fileName.endsWith('.js')) {
hashedFileName = fileName;
break;
}
}
if (hashedFileName) {
const proxyContent = `export * from './${hashedFileName}';\n`;
const proxyPath = resolve(options.dir, 'flock.js');
try {
writeFileSync(proxyPath, proxyContent);
console.log(`Generated proxy file: flock.js -> ${hashedFileName}`);
} catch (error) {
console.error(`Failed to create proxy file: ${error.message}`);
}
} else {
console.error('No hashed flock file found in the bundle.');
}
},
},
/*{
name: 'copy-bundle-with-fixed-name',
writeBundle(options, bundle) {
let jsFileName;
// Look for the main JavaScript file in the bundle
for (const fileName in bundle) {
if (fileName.endsWith('.js')) {
jsFileName = fileName;
break; // Assuming the first .js file is the main one; adjust if needed
}
}
if (jsFileName) {
const srcPath = resolve(options.dir, jsFileName);
const destPath = resolve(options.dir, 'flock.js');
try {
copyFileSync(srcPath, destPath);
console.log(`Copied ${jsFileName} to flock.js`);
} catch (error) {
console.error(`Failed to copy file: ${error.message}`);
}
} else {
console.error('No JavaScript file found in the bundle.');
}
},
},*/
{
name: 'copy-library-files',
writeBundle() {
copyFileSync('example.html', 'dist/example.html');
copyFileSync('flockdemo.html', 'dist/flockdemo.html');
},
},
],
server: {
host: '0.0.0.0',
fs: {
// Allow serving files outside of the root
allow: [
"../.."
]
},
allowedHosts: ['27c4c3b0-9860-47aa-a95d-03ca8acd6af0-00-2qj22wjmgrujn.picard.replit.dev', '1099a351-df60-40b5-bf61-4999bad0d153-00-4np7mg24c4rr.janeway.replit.dev'] //added this
},
optimizeDeps: { exclude: ["@babylonjs/havok"] },
build: {
assetsInlineLimit: 100000, // Set high enough to include font files
cssCodeSplit: false, // Disables CSS code splitting and inlines CSS into JavaScript
rollupOptions: {
input: 'index.html',
},
}
}