@mgz-app/viteforge 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -6
- package/dist/index.cjs +77 -25
- package/dist/index.mjs +77 -24
- package/dist/plugins/base64-assets.d.ts.map +1 -1
- package/dist/plugins/index.cjs +77 -25
- package/dist/plugins/index.mjs +77 -24
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -4,17 +4,58 @@ Build and serve utilities for Vite. Pre-configured presets for apps, packages, a
|
|
|
4
4
|
|
|
5
5
|
I built this for game jams. The goal: write a game, run one command, and get a single self-contained HTML file. No server required and no dependencies at runtime. The HTML file works like a binary: I can just send it to someone, they double-click it, and it runs (or, I host it anywhere and it just works). Everything (JavaScript, CSS, textures, models, shaders, audio) is inlined and compressed into one file that decompresses and boots itself in the browser.
|
|
6
6
|
|
|
7
|
-
Install
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add -D @mgz-app/viteforge vite
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then in your `vite.config.ts`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineAppConfig, defineConfig } from "@mgz-app/viteforge";
|
|
17
|
+
|
|
18
|
+
export default defineConfig(defineAppConfig());
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That's it. Build with `vite build`, dev with `vite`.
|
|
22
|
+
|
|
23
|
+
## Recommended Setup Install
|
|
24
|
+
|
|
25
|
+
With codestyle for ESLint, Prettier, and TypeScript
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pnpm add -D @mgz-app/viteforge @mgz-app/codestyle vite eslint prettier
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
ESLint Config:
|
|
32
|
+
```js
|
|
33
|
+
// eslint.config.mjs
|
|
34
|
+
export { default } from "@mgz-app/codestyle";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Prettier Config:
|
|
38
|
+
```js
|
|
39
|
+
// prettier.config.mjs
|
|
40
|
+
export { default } from "@mgz-app/codestyle/prettier";
|
|
41
|
+
```
|
|
42
|
+
TypeScript Config:
|
|
8
43
|
|
|
9
44
|
```json
|
|
45
|
+
// tsconfig.json
|
|
10
46
|
{
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
47
|
+
"extends": "@mgz-app/codestyle/tsconfig/base.json",
|
|
48
|
+
"compilerOptions": {
|
|
49
|
+
"outDir": "dist",
|
|
50
|
+
"rootDir": "src"
|
|
51
|
+
},
|
|
52
|
+
"include": ["src/**/*"]
|
|
15
53
|
}
|
|
16
54
|
```
|
|
17
55
|
|
|
56
|
+
> *See [@mgz-app/codestyle](https://github.com/marcogomez/codestyle) for full documentation.*
|
|
57
|
+
|
|
58
|
+
|
|
18
59
|
---
|
|
19
60
|
|
|
20
61
|
## Table of Contents
|
|
@@ -371,7 +412,7 @@ restartOnRebuildPlugin({
|
|
|
371
412
|
|
|
372
413
|
### `getGLSLPlugin()`
|
|
373
414
|
|
|
374
|
-
Enables importing GLSL and WGSL shader files. This is an async function
|
|
415
|
+
Enables importing GLSL and WGSL shader files. This is an async function, so use `await`.
|
|
375
416
|
|
|
376
417
|
```ts
|
|
377
418
|
// vite.config.ts
|
|
@@ -387,6 +428,21 @@ import fragmentShader from "./shaders/fragment.frag";
|
|
|
387
428
|
import computeShader from "./shaders/compute.wgsl";
|
|
388
429
|
```
|
|
389
430
|
|
|
431
|
+
If your config loader does not support top-level `await` (e.g. Electron Forge outputs CJS), wrap the config in an async function:
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
// vite.config.ts
|
|
435
|
+
import { defineConfig, getGLSLPlugin } from "@mgz-app/viteforge";
|
|
436
|
+
|
|
437
|
+
async function getConfig() {
|
|
438
|
+
return defineConfig({
|
|
439
|
+
plugins: [await getGLSLPlugin()]
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export default getConfig();
|
|
444
|
+
```
|
|
445
|
+
|
|
390
446
|
Supported: `.glsl`, `.wgsl`, `.vert`, `.vs`, `.frag`, `.fs`
|
|
391
447
|
|
|
392
448
|
Shaders support `#include` directives for composing shaders from multiple files.
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ var vitePluginHtml = require('vite-plugin-html');
|
|
|
5
5
|
var vitePluginSinglefile = require('vite-plugin-singlefile');
|
|
6
6
|
var crypto = require('crypto');
|
|
7
7
|
var fs5 = require('fs');
|
|
8
|
-
var mime = require('mime-types');
|
|
9
8
|
var module$1 = require('module');
|
|
10
9
|
var path = require('path');
|
|
11
10
|
var svgo = require('svgo');
|
|
@@ -23,7 +22,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
23
22
|
var dts__default = /*#__PURE__*/_interopDefault(dts);
|
|
24
23
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
25
24
|
var fs5__default = /*#__PURE__*/_interopDefault(fs5);
|
|
26
|
-
var mime__default = /*#__PURE__*/_interopDefault(mime);
|
|
27
25
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
28
26
|
var kill__default = /*#__PURE__*/_interopDefault(kill);
|
|
29
27
|
|
|
@@ -2295,6 +2293,77 @@ function injectNoncePlugin(options = {}) {
|
|
|
2295
2293
|
};
|
|
2296
2294
|
}
|
|
2297
2295
|
var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
2296
|
+
var MIME_TYPES = {
|
|
2297
|
+
// 3d models
|
|
2298
|
+
".glb": "model/gltf-binary",
|
|
2299
|
+
".gltf": "model/gltf+json",
|
|
2300
|
+
".fbx": "application/octet-stream",
|
|
2301
|
+
".obj": "model/obj",
|
|
2302
|
+
".stl": "model/stl",
|
|
2303
|
+
".ply": "application/x-ply",
|
|
2304
|
+
".dae": "model/vnd.collada+xml",
|
|
2305
|
+
".3ds": "application/x-3ds",
|
|
2306
|
+
".usdz": "model/vnd.usdz+zip",
|
|
2307
|
+
// images
|
|
2308
|
+
".png": "image/png",
|
|
2309
|
+
".jpg": "image/jpeg",
|
|
2310
|
+
".jpeg": "image/jpeg",
|
|
2311
|
+
".gif": "image/gif",
|
|
2312
|
+
".webp": "image/webp",
|
|
2313
|
+
".bmp": "image/bmp",
|
|
2314
|
+
".tga": "image/x-tga",
|
|
2315
|
+
".hdr": "image/vnd.radiance",
|
|
2316
|
+
".exr": "image/x-exr",
|
|
2317
|
+
".ktx": "image/ktx",
|
|
2318
|
+
".ktx2": "image/ktx2",
|
|
2319
|
+
".dds": "image/vnd-ms.dds",
|
|
2320
|
+
".basis": "application/octet-stream",
|
|
2321
|
+
".ico": "image/x-icon",
|
|
2322
|
+
".avif": "image/avif",
|
|
2323
|
+
// video
|
|
2324
|
+
".mp4": "video/mp4",
|
|
2325
|
+
".webm": "video/webm",
|
|
2326
|
+
".ogg": "video/ogg",
|
|
2327
|
+
".mov": "video/quicktime",
|
|
2328
|
+
".avi": "video/x-msvideo",
|
|
2329
|
+
".mkv": "video/x-matroska",
|
|
2330
|
+
// audio
|
|
2331
|
+
".mp3": "audio/mpeg",
|
|
2332
|
+
".wav": "audio/wav",
|
|
2333
|
+
".flac": "audio/flac",
|
|
2334
|
+
".aac": "audio/aac",
|
|
2335
|
+
".m4a": "audio/mp4",
|
|
2336
|
+
".opus": "audio/opus",
|
|
2337
|
+
".weba": "audio/webm",
|
|
2338
|
+
// fonts
|
|
2339
|
+
".ttf": "font/ttf",
|
|
2340
|
+
".otf": "font/otf",
|
|
2341
|
+
".woff": "font/woff",
|
|
2342
|
+
".woff2": "font/woff2",
|
|
2343
|
+
// binary/data
|
|
2344
|
+
".wasm": "application/wasm",
|
|
2345
|
+
".bin": "application/octet-stream",
|
|
2346
|
+
".img": "application/octet-stream",
|
|
2347
|
+
".dat": "application/octet-stream",
|
|
2348
|
+
".raw": "application/octet-stream",
|
|
2349
|
+
// LUTs
|
|
2350
|
+
".cube": "application/octet-stream",
|
|
2351
|
+
".3dl": "application/octet-stream",
|
|
2352
|
+
".csp": "application/octet-stream",
|
|
2353
|
+
".lut": "application/octet-stream",
|
|
2354
|
+
// shaders
|
|
2355
|
+
".glsl": "text/plain",
|
|
2356
|
+
".wgsl": "text/plain",
|
|
2357
|
+
".vert": "text/plain",
|
|
2358
|
+
".frag": "text/plain",
|
|
2359
|
+
".vs": "text/plain",
|
|
2360
|
+
".fs": "text/plain",
|
|
2361
|
+
".comp": "text/plain"
|
|
2362
|
+
};
|
|
2363
|
+
function lookupMime(ext) {
|
|
2364
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2365
|
+
}
|
|
2366
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2298
2367
|
function base64AssetPlugin() {
|
|
2299
2368
|
return {
|
|
2300
2369
|
name: "vite-base64-assets",
|
|
@@ -2333,33 +2402,11 @@ function base64AssetPlugin() {
|
|
|
2333
2402
|
if (!path__default.default.isAbsolute(cleanId)) {
|
|
2334
2403
|
return null;
|
|
2335
2404
|
}
|
|
2336
|
-
const extension = path__default.default.extname(cleanId);
|
|
2337
|
-
const mimeType = mime__default.default.lookup(extension) || "application/octet-stream";
|
|
2338
|
-
const allowedExtensions = [
|
|
2339
|
-
".glb",
|
|
2340
|
-
".gltf",
|
|
2341
|
-
".fbx",
|
|
2342
|
-
".obj",
|
|
2343
|
-
".png",
|
|
2344
|
-
".jpeg",
|
|
2345
|
-
".jpg",
|
|
2346
|
-
".gif",
|
|
2347
|
-
".webm",
|
|
2348
|
-
".mp4",
|
|
2349
|
-
".mp3",
|
|
2350
|
-
".ogg",
|
|
2351
|
-
".wav",
|
|
2352
|
-
".ttf",
|
|
2353
|
-
".otf"
|
|
2354
|
-
];
|
|
2405
|
+
const extension = path__default.default.extname(cleanId).toLowerCase();
|
|
2355
2406
|
if (hasBase64Query) {
|
|
2356
2407
|
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2357
2408
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2358
2409
|
}
|
|
2359
|
-
if (allowedExtensions.includes(extension)) {
|
|
2360
|
-
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2361
|
-
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2362
|
-
}
|
|
2363
2410
|
if (extension === ".svg") {
|
|
2364
2411
|
const svg = fs5__default.default.readFileSync(cleanId, "utf8");
|
|
2365
2412
|
const optimized = svgo.optimize(svg, {
|
|
@@ -2369,6 +2416,11 @@ function base64AssetPlugin() {
|
|
|
2369
2416
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2370
2417
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2371
2418
|
}
|
|
2419
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2420
|
+
const mimeType = lookupMime(extension);
|
|
2421
|
+
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2422
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2423
|
+
}
|
|
2372
2424
|
return null;
|
|
2373
2425
|
}
|
|
2374
2426
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import { createHtmlPlugin } from 'vite-plugin-html';
|
|
|
4
4
|
import { viteSingleFile } from 'vite-plugin-singlefile';
|
|
5
5
|
import crypto, { createHash } from 'crypto';
|
|
6
6
|
import fs5, { readFileSync } from 'fs';
|
|
7
|
-
import mime from 'mime-types';
|
|
8
7
|
import { createRequire } from 'module';
|
|
9
8
|
import path, { sep, posix, dirname, resolve, extname } from 'path';
|
|
10
9
|
export { resolve } from 'path';
|
|
@@ -2286,6 +2285,77 @@ function injectNoncePlugin(options = {}) {
|
|
|
2286
2285
|
};
|
|
2287
2286
|
}
|
|
2288
2287
|
var require2 = createRequire(import.meta.url);
|
|
2288
|
+
var MIME_TYPES = {
|
|
2289
|
+
// 3d models
|
|
2290
|
+
".glb": "model/gltf-binary",
|
|
2291
|
+
".gltf": "model/gltf+json",
|
|
2292
|
+
".fbx": "application/octet-stream",
|
|
2293
|
+
".obj": "model/obj",
|
|
2294
|
+
".stl": "model/stl",
|
|
2295
|
+
".ply": "application/x-ply",
|
|
2296
|
+
".dae": "model/vnd.collada+xml",
|
|
2297
|
+
".3ds": "application/x-3ds",
|
|
2298
|
+
".usdz": "model/vnd.usdz+zip",
|
|
2299
|
+
// images
|
|
2300
|
+
".png": "image/png",
|
|
2301
|
+
".jpg": "image/jpeg",
|
|
2302
|
+
".jpeg": "image/jpeg",
|
|
2303
|
+
".gif": "image/gif",
|
|
2304
|
+
".webp": "image/webp",
|
|
2305
|
+
".bmp": "image/bmp",
|
|
2306
|
+
".tga": "image/x-tga",
|
|
2307
|
+
".hdr": "image/vnd.radiance",
|
|
2308
|
+
".exr": "image/x-exr",
|
|
2309
|
+
".ktx": "image/ktx",
|
|
2310
|
+
".ktx2": "image/ktx2",
|
|
2311
|
+
".dds": "image/vnd-ms.dds",
|
|
2312
|
+
".basis": "application/octet-stream",
|
|
2313
|
+
".ico": "image/x-icon",
|
|
2314
|
+
".avif": "image/avif",
|
|
2315
|
+
// video
|
|
2316
|
+
".mp4": "video/mp4",
|
|
2317
|
+
".webm": "video/webm",
|
|
2318
|
+
".ogg": "video/ogg",
|
|
2319
|
+
".mov": "video/quicktime",
|
|
2320
|
+
".avi": "video/x-msvideo",
|
|
2321
|
+
".mkv": "video/x-matroska",
|
|
2322
|
+
// audio
|
|
2323
|
+
".mp3": "audio/mpeg",
|
|
2324
|
+
".wav": "audio/wav",
|
|
2325
|
+
".flac": "audio/flac",
|
|
2326
|
+
".aac": "audio/aac",
|
|
2327
|
+
".m4a": "audio/mp4",
|
|
2328
|
+
".opus": "audio/opus",
|
|
2329
|
+
".weba": "audio/webm",
|
|
2330
|
+
// fonts
|
|
2331
|
+
".ttf": "font/ttf",
|
|
2332
|
+
".otf": "font/otf",
|
|
2333
|
+
".woff": "font/woff",
|
|
2334
|
+
".woff2": "font/woff2",
|
|
2335
|
+
// binary/data
|
|
2336
|
+
".wasm": "application/wasm",
|
|
2337
|
+
".bin": "application/octet-stream",
|
|
2338
|
+
".img": "application/octet-stream",
|
|
2339
|
+
".dat": "application/octet-stream",
|
|
2340
|
+
".raw": "application/octet-stream",
|
|
2341
|
+
// LUTs
|
|
2342
|
+
".cube": "application/octet-stream",
|
|
2343
|
+
".3dl": "application/octet-stream",
|
|
2344
|
+
".csp": "application/octet-stream",
|
|
2345
|
+
".lut": "application/octet-stream",
|
|
2346
|
+
// shaders
|
|
2347
|
+
".glsl": "text/plain",
|
|
2348
|
+
".wgsl": "text/plain",
|
|
2349
|
+
".vert": "text/plain",
|
|
2350
|
+
".frag": "text/plain",
|
|
2351
|
+
".vs": "text/plain",
|
|
2352
|
+
".fs": "text/plain",
|
|
2353
|
+
".comp": "text/plain"
|
|
2354
|
+
};
|
|
2355
|
+
function lookupMime(ext) {
|
|
2356
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2357
|
+
}
|
|
2358
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2289
2359
|
function base64AssetPlugin() {
|
|
2290
2360
|
return {
|
|
2291
2361
|
name: "vite-base64-assets",
|
|
@@ -2324,33 +2394,11 @@ function base64AssetPlugin() {
|
|
|
2324
2394
|
if (!path.isAbsolute(cleanId)) {
|
|
2325
2395
|
return null;
|
|
2326
2396
|
}
|
|
2327
|
-
const extension = path.extname(cleanId);
|
|
2328
|
-
const mimeType = mime.lookup(extension) || "application/octet-stream";
|
|
2329
|
-
const allowedExtensions = [
|
|
2330
|
-
".glb",
|
|
2331
|
-
".gltf",
|
|
2332
|
-
".fbx",
|
|
2333
|
-
".obj",
|
|
2334
|
-
".png",
|
|
2335
|
-
".jpeg",
|
|
2336
|
-
".jpg",
|
|
2337
|
-
".gif",
|
|
2338
|
-
".webm",
|
|
2339
|
-
".mp4",
|
|
2340
|
-
".mp3",
|
|
2341
|
-
".ogg",
|
|
2342
|
-
".wav",
|
|
2343
|
-
".ttf",
|
|
2344
|
-
".otf"
|
|
2345
|
-
];
|
|
2397
|
+
const extension = path.extname(cleanId).toLowerCase();
|
|
2346
2398
|
if (hasBase64Query) {
|
|
2347
2399
|
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2348
2400
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2349
2401
|
}
|
|
2350
|
-
if (allowedExtensions.includes(extension)) {
|
|
2351
|
-
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2352
|
-
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2353
|
-
}
|
|
2354
2402
|
if (extension === ".svg") {
|
|
2355
2403
|
const svg = fs5.readFileSync(cleanId, "utf8");
|
|
2356
2404
|
const optimized = optimize(svg, {
|
|
@@ -2360,6 +2408,11 @@ function base64AssetPlugin() {
|
|
|
2360
2408
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2361
2409
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2362
2410
|
}
|
|
2411
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2412
|
+
const mimeType = lookupMime(extension);
|
|
2413
|
+
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2414
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2415
|
+
}
|
|
2363
2416
|
return null;
|
|
2364
2417
|
}
|
|
2365
2418
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-assets.d.ts","sourceRoot":"","sources":["../../src/plugins/base64-assets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base64-assets.d.ts","sourceRoot":"","sources":["../../src/plugins/base64-assets.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AA+EnC,wBAAgB,iBAAiB,IAAI,MAAM,CAsE1C"}
|
package/dist/plugins/index.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var fs5 = require('fs');
|
|
5
|
-
var mime = require('mime-types');
|
|
6
5
|
var module$1 = require('module');
|
|
7
6
|
var path = require('path');
|
|
8
7
|
var svgo = require('svgo');
|
|
@@ -19,7 +18,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
19
18
|
|
|
20
19
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
21
20
|
var fs5__default = /*#__PURE__*/_interopDefault(fs5);
|
|
22
|
-
var mime__default = /*#__PURE__*/_interopDefault(mime);
|
|
23
21
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
24
22
|
var kill__default = /*#__PURE__*/_interopDefault(kill);
|
|
25
23
|
|
|
@@ -2291,6 +2289,77 @@ function injectNoncePlugin(options = {}) {
|
|
|
2291
2289
|
};
|
|
2292
2290
|
}
|
|
2293
2291
|
var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
2292
|
+
var MIME_TYPES = {
|
|
2293
|
+
// 3d models
|
|
2294
|
+
".glb": "model/gltf-binary",
|
|
2295
|
+
".gltf": "model/gltf+json",
|
|
2296
|
+
".fbx": "application/octet-stream",
|
|
2297
|
+
".obj": "model/obj",
|
|
2298
|
+
".stl": "model/stl",
|
|
2299
|
+
".ply": "application/x-ply",
|
|
2300
|
+
".dae": "model/vnd.collada+xml",
|
|
2301
|
+
".3ds": "application/x-3ds",
|
|
2302
|
+
".usdz": "model/vnd.usdz+zip",
|
|
2303
|
+
// images
|
|
2304
|
+
".png": "image/png",
|
|
2305
|
+
".jpg": "image/jpeg",
|
|
2306
|
+
".jpeg": "image/jpeg",
|
|
2307
|
+
".gif": "image/gif",
|
|
2308
|
+
".webp": "image/webp",
|
|
2309
|
+
".bmp": "image/bmp",
|
|
2310
|
+
".tga": "image/x-tga",
|
|
2311
|
+
".hdr": "image/vnd.radiance",
|
|
2312
|
+
".exr": "image/x-exr",
|
|
2313
|
+
".ktx": "image/ktx",
|
|
2314
|
+
".ktx2": "image/ktx2",
|
|
2315
|
+
".dds": "image/vnd-ms.dds",
|
|
2316
|
+
".basis": "application/octet-stream",
|
|
2317
|
+
".ico": "image/x-icon",
|
|
2318
|
+
".avif": "image/avif",
|
|
2319
|
+
// video
|
|
2320
|
+
".mp4": "video/mp4",
|
|
2321
|
+
".webm": "video/webm",
|
|
2322
|
+
".ogg": "video/ogg",
|
|
2323
|
+
".mov": "video/quicktime",
|
|
2324
|
+
".avi": "video/x-msvideo",
|
|
2325
|
+
".mkv": "video/x-matroska",
|
|
2326
|
+
// audio
|
|
2327
|
+
".mp3": "audio/mpeg",
|
|
2328
|
+
".wav": "audio/wav",
|
|
2329
|
+
".flac": "audio/flac",
|
|
2330
|
+
".aac": "audio/aac",
|
|
2331
|
+
".m4a": "audio/mp4",
|
|
2332
|
+
".opus": "audio/opus",
|
|
2333
|
+
".weba": "audio/webm",
|
|
2334
|
+
// fonts
|
|
2335
|
+
".ttf": "font/ttf",
|
|
2336
|
+
".otf": "font/otf",
|
|
2337
|
+
".woff": "font/woff",
|
|
2338
|
+
".woff2": "font/woff2",
|
|
2339
|
+
// binary/data
|
|
2340
|
+
".wasm": "application/wasm",
|
|
2341
|
+
".bin": "application/octet-stream",
|
|
2342
|
+
".img": "application/octet-stream",
|
|
2343
|
+
".dat": "application/octet-stream",
|
|
2344
|
+
".raw": "application/octet-stream",
|
|
2345
|
+
// LUTs
|
|
2346
|
+
".cube": "application/octet-stream",
|
|
2347
|
+
".3dl": "application/octet-stream",
|
|
2348
|
+
".csp": "application/octet-stream",
|
|
2349
|
+
".lut": "application/octet-stream",
|
|
2350
|
+
// shaders
|
|
2351
|
+
".glsl": "text/plain",
|
|
2352
|
+
".wgsl": "text/plain",
|
|
2353
|
+
".vert": "text/plain",
|
|
2354
|
+
".frag": "text/plain",
|
|
2355
|
+
".vs": "text/plain",
|
|
2356
|
+
".fs": "text/plain",
|
|
2357
|
+
".comp": "text/plain"
|
|
2358
|
+
};
|
|
2359
|
+
function lookupMime(ext) {
|
|
2360
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2361
|
+
}
|
|
2362
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2294
2363
|
function base64AssetPlugin() {
|
|
2295
2364
|
return {
|
|
2296
2365
|
name: "vite-base64-assets",
|
|
@@ -2329,33 +2398,11 @@ function base64AssetPlugin() {
|
|
|
2329
2398
|
if (!path__default.default.isAbsolute(cleanId)) {
|
|
2330
2399
|
return null;
|
|
2331
2400
|
}
|
|
2332
|
-
const extension = path__default.default.extname(cleanId);
|
|
2333
|
-
const mimeType = mime__default.default.lookup(extension) || "application/octet-stream";
|
|
2334
|
-
const allowedExtensions = [
|
|
2335
|
-
".glb",
|
|
2336
|
-
".gltf",
|
|
2337
|
-
".fbx",
|
|
2338
|
-
".obj",
|
|
2339
|
-
".png",
|
|
2340
|
-
".jpeg",
|
|
2341
|
-
".jpg",
|
|
2342
|
-
".gif",
|
|
2343
|
-
".webm",
|
|
2344
|
-
".mp4",
|
|
2345
|
-
".mp3",
|
|
2346
|
-
".ogg",
|
|
2347
|
-
".wav",
|
|
2348
|
-
".ttf",
|
|
2349
|
-
".otf"
|
|
2350
|
-
];
|
|
2401
|
+
const extension = path__default.default.extname(cleanId).toLowerCase();
|
|
2351
2402
|
if (hasBase64Query) {
|
|
2352
2403
|
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2353
2404
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2354
2405
|
}
|
|
2355
|
-
if (allowedExtensions.includes(extension)) {
|
|
2356
|
-
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2357
|
-
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2358
|
-
}
|
|
2359
2406
|
if (extension === ".svg") {
|
|
2360
2407
|
const svg = fs5__default.default.readFileSync(cleanId, "utf8");
|
|
2361
2408
|
const optimized = svgo.optimize(svg, {
|
|
@@ -2365,6 +2412,11 @@ function base64AssetPlugin() {
|
|
|
2365
2412
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2366
2413
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2367
2414
|
}
|
|
2415
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2416
|
+
const mimeType = lookupMime(extension);
|
|
2417
|
+
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2418
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2419
|
+
}
|
|
2368
2420
|
return null;
|
|
2369
2421
|
}
|
|
2370
2422
|
};
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import crypto, { createHash } from 'crypto';
|
|
2
2
|
import fs5, { readFileSync } from 'fs';
|
|
3
|
-
import mime from 'mime-types';
|
|
4
3
|
import { createRequire } from 'module';
|
|
5
4
|
import path, { sep, posix, dirname, resolve, extname } from 'path';
|
|
6
5
|
import { optimize } from 'svgo';
|
|
@@ -2280,6 +2279,77 @@ function injectNoncePlugin(options = {}) {
|
|
|
2280
2279
|
};
|
|
2281
2280
|
}
|
|
2282
2281
|
var require2 = createRequire(import.meta.url);
|
|
2282
|
+
var MIME_TYPES = {
|
|
2283
|
+
// 3d models
|
|
2284
|
+
".glb": "model/gltf-binary",
|
|
2285
|
+
".gltf": "model/gltf+json",
|
|
2286
|
+
".fbx": "application/octet-stream",
|
|
2287
|
+
".obj": "model/obj",
|
|
2288
|
+
".stl": "model/stl",
|
|
2289
|
+
".ply": "application/x-ply",
|
|
2290
|
+
".dae": "model/vnd.collada+xml",
|
|
2291
|
+
".3ds": "application/x-3ds",
|
|
2292
|
+
".usdz": "model/vnd.usdz+zip",
|
|
2293
|
+
// images
|
|
2294
|
+
".png": "image/png",
|
|
2295
|
+
".jpg": "image/jpeg",
|
|
2296
|
+
".jpeg": "image/jpeg",
|
|
2297
|
+
".gif": "image/gif",
|
|
2298
|
+
".webp": "image/webp",
|
|
2299
|
+
".bmp": "image/bmp",
|
|
2300
|
+
".tga": "image/x-tga",
|
|
2301
|
+
".hdr": "image/vnd.radiance",
|
|
2302
|
+
".exr": "image/x-exr",
|
|
2303
|
+
".ktx": "image/ktx",
|
|
2304
|
+
".ktx2": "image/ktx2",
|
|
2305
|
+
".dds": "image/vnd-ms.dds",
|
|
2306
|
+
".basis": "application/octet-stream",
|
|
2307
|
+
".ico": "image/x-icon",
|
|
2308
|
+
".avif": "image/avif",
|
|
2309
|
+
// video
|
|
2310
|
+
".mp4": "video/mp4",
|
|
2311
|
+
".webm": "video/webm",
|
|
2312
|
+
".ogg": "video/ogg",
|
|
2313
|
+
".mov": "video/quicktime",
|
|
2314
|
+
".avi": "video/x-msvideo",
|
|
2315
|
+
".mkv": "video/x-matroska",
|
|
2316
|
+
// audio
|
|
2317
|
+
".mp3": "audio/mpeg",
|
|
2318
|
+
".wav": "audio/wav",
|
|
2319
|
+
".flac": "audio/flac",
|
|
2320
|
+
".aac": "audio/aac",
|
|
2321
|
+
".m4a": "audio/mp4",
|
|
2322
|
+
".opus": "audio/opus",
|
|
2323
|
+
".weba": "audio/webm",
|
|
2324
|
+
// fonts
|
|
2325
|
+
".ttf": "font/ttf",
|
|
2326
|
+
".otf": "font/otf",
|
|
2327
|
+
".woff": "font/woff",
|
|
2328
|
+
".woff2": "font/woff2",
|
|
2329
|
+
// binary/data
|
|
2330
|
+
".wasm": "application/wasm",
|
|
2331
|
+
".bin": "application/octet-stream",
|
|
2332
|
+
".img": "application/octet-stream",
|
|
2333
|
+
".dat": "application/octet-stream",
|
|
2334
|
+
".raw": "application/octet-stream",
|
|
2335
|
+
// LUTs
|
|
2336
|
+
".cube": "application/octet-stream",
|
|
2337
|
+
".3dl": "application/octet-stream",
|
|
2338
|
+
".csp": "application/octet-stream",
|
|
2339
|
+
".lut": "application/octet-stream",
|
|
2340
|
+
// shaders
|
|
2341
|
+
".glsl": "text/plain",
|
|
2342
|
+
".wgsl": "text/plain",
|
|
2343
|
+
".vert": "text/plain",
|
|
2344
|
+
".frag": "text/plain",
|
|
2345
|
+
".vs": "text/plain",
|
|
2346
|
+
".fs": "text/plain",
|
|
2347
|
+
".comp": "text/plain"
|
|
2348
|
+
};
|
|
2349
|
+
function lookupMime(ext) {
|
|
2350
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2351
|
+
}
|
|
2352
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2283
2353
|
function base64AssetPlugin() {
|
|
2284
2354
|
return {
|
|
2285
2355
|
name: "vite-base64-assets",
|
|
@@ -2318,33 +2388,11 @@ function base64AssetPlugin() {
|
|
|
2318
2388
|
if (!path.isAbsolute(cleanId)) {
|
|
2319
2389
|
return null;
|
|
2320
2390
|
}
|
|
2321
|
-
const extension = path.extname(cleanId);
|
|
2322
|
-
const mimeType = mime.lookup(extension) || "application/octet-stream";
|
|
2323
|
-
const allowedExtensions = [
|
|
2324
|
-
".glb",
|
|
2325
|
-
".gltf",
|
|
2326
|
-
".fbx",
|
|
2327
|
-
".obj",
|
|
2328
|
-
".png",
|
|
2329
|
-
".jpeg",
|
|
2330
|
-
".jpg",
|
|
2331
|
-
".gif",
|
|
2332
|
-
".webm",
|
|
2333
|
-
".mp4",
|
|
2334
|
-
".mp3",
|
|
2335
|
-
".ogg",
|
|
2336
|
-
".wav",
|
|
2337
|
-
".ttf",
|
|
2338
|
-
".otf"
|
|
2339
|
-
];
|
|
2391
|
+
const extension = path.extname(cleanId).toLowerCase();
|
|
2340
2392
|
if (hasBase64Query) {
|
|
2341
2393
|
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2342
2394
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2343
2395
|
}
|
|
2344
|
-
if (allowedExtensions.includes(extension)) {
|
|
2345
|
-
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2346
|
-
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2347
|
-
}
|
|
2348
2396
|
if (extension === ".svg") {
|
|
2349
2397
|
const svg = fs5.readFileSync(cleanId, "utf8");
|
|
2350
2398
|
const optimized = optimize(svg, {
|
|
@@ -2354,6 +2402,11 @@ function base64AssetPlugin() {
|
|
|
2354
2402
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2355
2403
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2356
2404
|
}
|
|
2405
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2406
|
+
const mimeType = lookupMime(extension);
|
|
2407
|
+
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2408
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2409
|
+
}
|
|
2357
2410
|
return null;
|
|
2358
2411
|
}
|
|
2359
2412
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mgz-app/viteforge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Build and serve utilities for Vite. Pre-configured presets for apps, packages, and libraries.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@changesets/cli": "^2.29.4",
|
|
36
36
|
"@mgz-app/codestyle": "^1.1.0",
|
|
37
|
-
"@types/mime-types": "^3.0.1",
|
|
38
37
|
"@types/node": "^25.0.3",
|
|
39
38
|
"@types/pako": "^2.0.4",
|
|
40
39
|
"@types/resolve": "^1.20.6",
|
|
41
40
|
"esbuild": "^0.25.12",
|
|
42
41
|
"dotenv": "^17.4.2",
|
|
43
42
|
"eslint": "^9.39.4",
|
|
43
|
+
"prettier": "^3.8.3",
|
|
44
44
|
"resolve": "^1.22.12",
|
|
45
45
|
"rimraf": "^6.1.3",
|
|
46
46
|
"tsup": "^8.5.1",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"vitest": "^4.1.8"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"mime-types": "^3.0.2",
|
|
52
51
|
"pako": "^2.1.0",
|
|
53
52
|
"svgo": "^4.0.1",
|
|
54
53
|
"tree-kill": "^1.2.2",
|