@mgz-app/viteforge 1.0.0 → 1.1.0
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 +84 -25
- package/dist/index.mjs +84 -24
- package/dist/plugins/base64-assets.d.ts.map +1 -1
- package/dist/plugins/index.cjs +84 -25
- package/dist/plugins/index.mjs +84 -24
- package/package.json +16 -17
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,84 @@ 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
|
+
// documents/config
|
|
2363
|
+
".json": "application/json",
|
|
2364
|
+
".xml": "application/xml",
|
|
2365
|
+
".csv": "text/csv",
|
|
2366
|
+
".toml": "application/toml",
|
|
2367
|
+
".yaml": "text/yaml",
|
|
2368
|
+
".yml": "text/yaml"
|
|
2369
|
+
};
|
|
2370
|
+
function lookupMime(ext) {
|
|
2371
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2372
|
+
}
|
|
2373
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2298
2374
|
function base64AssetPlugin() {
|
|
2299
2375
|
return {
|
|
2300
2376
|
name: "vite-base64-assets",
|
|
@@ -2333,33 +2409,11 @@ function base64AssetPlugin() {
|
|
|
2333
2409
|
if (!path__default.default.isAbsolute(cleanId)) {
|
|
2334
2410
|
return null;
|
|
2335
2411
|
}
|
|
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
|
-
];
|
|
2412
|
+
const extension = path__default.default.extname(cleanId).toLowerCase();
|
|
2355
2413
|
if (hasBase64Query) {
|
|
2356
2414
|
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2357
2415
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2358
2416
|
}
|
|
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
2417
|
if (extension === ".svg") {
|
|
2364
2418
|
const svg = fs5__default.default.readFileSync(cleanId, "utf8");
|
|
2365
2419
|
const optimized = svgo.optimize(svg, {
|
|
@@ -2369,6 +2423,11 @@ function base64AssetPlugin() {
|
|
|
2369
2423
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2370
2424
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2371
2425
|
}
|
|
2426
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2427
|
+
const mimeType = lookupMime(extension);
|
|
2428
|
+
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2429
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2430
|
+
}
|
|
2372
2431
|
return null;
|
|
2373
2432
|
}
|
|
2374
2433
|
};
|
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,84 @@ 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
|
+
// documents/config
|
|
2355
|
+
".json": "application/json",
|
|
2356
|
+
".xml": "application/xml",
|
|
2357
|
+
".csv": "text/csv",
|
|
2358
|
+
".toml": "application/toml",
|
|
2359
|
+
".yaml": "text/yaml",
|
|
2360
|
+
".yml": "text/yaml"
|
|
2361
|
+
};
|
|
2362
|
+
function lookupMime(ext) {
|
|
2363
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2364
|
+
}
|
|
2365
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2289
2366
|
function base64AssetPlugin() {
|
|
2290
2367
|
return {
|
|
2291
2368
|
name: "vite-base64-assets",
|
|
@@ -2324,33 +2401,11 @@ function base64AssetPlugin() {
|
|
|
2324
2401
|
if (!path.isAbsolute(cleanId)) {
|
|
2325
2402
|
return null;
|
|
2326
2403
|
}
|
|
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
|
-
];
|
|
2404
|
+
const extension = path.extname(cleanId).toLowerCase();
|
|
2346
2405
|
if (hasBase64Query) {
|
|
2347
2406
|
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2348
2407
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2349
2408
|
}
|
|
2350
|
-
if (allowedExtensions.includes(extension)) {
|
|
2351
|
-
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2352
|
-
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2353
|
-
}
|
|
2354
2409
|
if (extension === ".svg") {
|
|
2355
2410
|
const svg = fs5.readFileSync(cleanId, "utf8");
|
|
2356
2411
|
const optimized = optimize(svg, {
|
|
@@ -2360,6 +2415,11 @@ function base64AssetPlugin() {
|
|
|
2360
2415
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2361
2416
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2362
2417
|
}
|
|
2418
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2419
|
+
const mimeType = lookupMime(extension);
|
|
2420
|
+
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2421
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2422
|
+
}
|
|
2363
2423
|
return null;
|
|
2364
2424
|
}
|
|
2365
2425
|
};
|
|
@@ -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;AAsFnC,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,84 @@ 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
|
+
// documents/config
|
|
2359
|
+
".json": "application/json",
|
|
2360
|
+
".xml": "application/xml",
|
|
2361
|
+
".csv": "text/csv",
|
|
2362
|
+
".toml": "application/toml",
|
|
2363
|
+
".yaml": "text/yaml",
|
|
2364
|
+
".yml": "text/yaml"
|
|
2365
|
+
};
|
|
2366
|
+
function lookupMime(ext) {
|
|
2367
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2368
|
+
}
|
|
2369
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2294
2370
|
function base64AssetPlugin() {
|
|
2295
2371
|
return {
|
|
2296
2372
|
name: "vite-base64-assets",
|
|
@@ -2329,33 +2405,11 @@ function base64AssetPlugin() {
|
|
|
2329
2405
|
if (!path__default.default.isAbsolute(cleanId)) {
|
|
2330
2406
|
return null;
|
|
2331
2407
|
}
|
|
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
|
-
];
|
|
2408
|
+
const extension = path__default.default.extname(cleanId).toLowerCase();
|
|
2351
2409
|
if (hasBase64Query) {
|
|
2352
2410
|
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2353
2411
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2354
2412
|
}
|
|
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
2413
|
if (extension === ".svg") {
|
|
2360
2414
|
const svg = fs5__default.default.readFileSync(cleanId, "utf8");
|
|
2361
2415
|
const optimized = svgo.optimize(svg, {
|
|
@@ -2365,6 +2419,11 @@ function base64AssetPlugin() {
|
|
|
2365
2419
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2366
2420
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2367
2421
|
}
|
|
2422
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2423
|
+
const mimeType = lookupMime(extension);
|
|
2424
|
+
const fileBuffer = fs5__default.default.readFileSync(cleanId);
|
|
2425
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2426
|
+
}
|
|
2368
2427
|
return null;
|
|
2369
2428
|
}
|
|
2370
2429
|
};
|
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,84 @@ 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
|
+
// documents/config
|
|
2349
|
+
".json": "application/json",
|
|
2350
|
+
".xml": "application/xml",
|
|
2351
|
+
".csv": "text/csv",
|
|
2352
|
+
".toml": "application/toml",
|
|
2353
|
+
".yaml": "text/yaml",
|
|
2354
|
+
".yml": "text/yaml"
|
|
2355
|
+
};
|
|
2356
|
+
function lookupMime(ext) {
|
|
2357
|
+
return MIME_TYPES[ext.toLowerCase()] || "application/octet-stream";
|
|
2358
|
+
}
|
|
2359
|
+
var ALLOWED_EXTENSIONS = new Set(Object.keys(MIME_TYPES));
|
|
2283
2360
|
function base64AssetPlugin() {
|
|
2284
2361
|
return {
|
|
2285
2362
|
name: "vite-base64-assets",
|
|
@@ -2318,33 +2395,11 @@ function base64AssetPlugin() {
|
|
|
2318
2395
|
if (!path.isAbsolute(cleanId)) {
|
|
2319
2396
|
return null;
|
|
2320
2397
|
}
|
|
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
|
-
];
|
|
2398
|
+
const extension = path.extname(cleanId).toLowerCase();
|
|
2340
2399
|
if (hasBase64Query) {
|
|
2341
2400
|
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2342
2401
|
return `export default "${fileBuffer.toString("base64")}";`;
|
|
2343
2402
|
}
|
|
2344
|
-
if (allowedExtensions.includes(extension)) {
|
|
2345
|
-
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2346
|
-
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2347
|
-
}
|
|
2348
2403
|
if (extension === ".svg") {
|
|
2349
2404
|
const svg = fs5.readFileSync(cleanId, "utf8");
|
|
2350
2405
|
const optimized = optimize(svg, {
|
|
@@ -2354,6 +2409,11 @@ function base64AssetPlugin() {
|
|
|
2354
2409
|
const encoded = encodeURIComponent(optimized.data).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
2355
2410
|
return `export default "data:image/svg+xml;charset=utf-8,${encoded}"`;
|
|
2356
2411
|
}
|
|
2412
|
+
if (ALLOWED_EXTENSIONS.has(extension)) {
|
|
2413
|
+
const mimeType = lookupMime(extension);
|
|
2414
|
+
const fileBuffer = fs5.readFileSync(cleanId);
|
|
2415
|
+
return `export default "data:${mimeType};base64,${fileBuffer.toString("base64")}"`;
|
|
2416
|
+
}
|
|
2357
2417
|
return null;
|
|
2358
2418
|
}
|
|
2359
2419
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mgz-app/viteforge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -31,27 +31,16 @@
|
|
|
31
31
|
"import": "./dist/plugins/index.mjs"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "rimraf dist tsconfig.tsbuildinfo && tsup && tsc --emitDeclarationOnly",
|
|
36
|
-
"dev": "tsup --watch",
|
|
37
|
-
"type-check": "tsc --noEmit",
|
|
38
|
-
"lint": "eslint src --max-warnings 0",
|
|
39
|
-
"lint-fix": "eslint src --fix",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"changeset": "changeset",
|
|
42
|
-
"version": "changeset version",
|
|
43
|
-
"release": "changeset publish"
|
|
44
|
-
},
|
|
45
34
|
"devDependencies": {
|
|
46
35
|
"@changesets/cli": "^2.29.4",
|
|
47
36
|
"@mgz-app/codestyle": "^1.1.0",
|
|
48
|
-
"@types/mime-types": "^3.0.1",
|
|
49
37
|
"@types/node": "^25.0.3",
|
|
50
38
|
"@types/pako": "^2.0.4",
|
|
51
39
|
"@types/resolve": "^1.20.6",
|
|
52
40
|
"esbuild": "^0.25.12",
|
|
53
41
|
"dotenv": "^17.4.2",
|
|
54
42
|
"eslint": "^9.39.4",
|
|
43
|
+
"prettier": "^3.8.3",
|
|
55
44
|
"resolve": "^1.22.12",
|
|
56
45
|
"rimraf": "^6.1.3",
|
|
57
46
|
"tsup": "^8.5.1",
|
|
@@ -59,7 +48,6 @@
|
|
|
59
48
|
"vitest": "^4.1.8"
|
|
60
49
|
},
|
|
61
50
|
"dependencies": {
|
|
62
|
-
"mime-types": "^3.0.2",
|
|
63
51
|
"pako": "^2.1.0",
|
|
64
52
|
"svgo": "^4.0.1",
|
|
65
53
|
"tree-kill": "^1.2.2",
|
|
@@ -69,7 +57,18 @@
|
|
|
69
57
|
"vite-plugin-singlefile": "^2.3.3"
|
|
70
58
|
},
|
|
71
59
|
"publishConfig": {
|
|
72
|
-
"access": "public"
|
|
60
|
+
"access": "public",
|
|
61
|
+
"provenance": true
|
|
73
62
|
},
|
|
74
|
-
"
|
|
75
|
-
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "rimraf dist tsconfig.tsbuildinfo && tsup && tsc --emitDeclarationOnly",
|
|
65
|
+
"dev": "tsup --watch",
|
|
66
|
+
"type-check": "tsc --noEmit",
|
|
67
|
+
"lint": "eslint src --max-warnings 0",
|
|
68
|
+
"lint-fix": "eslint src --fix",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"changeset": "changeset",
|
|
71
|
+
"version": "changeset version",
|
|
72
|
+
"release": "changeset publish"
|
|
73
|
+
}
|
|
74
|
+
}
|