svelte-bundle 0.3.0 → 0.4.0-beta.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/dist/cli.js +152 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3004,7 +3004,8 @@ async function runCreatePrompts(nameArg, pmArg) {
|
|
|
3004
3004
|
{ value: "tailwind", label: "Tailwind CSS", hint: "utility-first CSS framework" },
|
|
3005
3005
|
{ value: "eslint", label: "ESLint", hint: "code linting" },
|
|
3006
3006
|
{ value: "prettier", label: "Prettier", hint: "code formatting" },
|
|
3007
|
-
{ value: "vitest", label: "Vitest", hint: "unit testing" }
|
|
3007
|
+
{ value: "vitest", label: "Vitest", hint: "unit testing" },
|
|
3008
|
+
{ value: "playwright", label: "Playwright", hint: "end-to-end testing" }
|
|
3008
3009
|
],
|
|
3009
3010
|
required: false
|
|
3010
3011
|
}));
|
|
@@ -3210,6 +3211,51 @@ describe('example', () => {
|
|
|
3210
3211
|
expect(true).toBe(true);
|
|
3211
3212
|
});
|
|
3212
3213
|
});
|
|
3214
|
+
`
|
|
3215
|
+
}
|
|
3216
|
+
]
|
|
3217
|
+
},
|
|
3218
|
+
playwright: {
|
|
3219
|
+
devDependencies: {
|
|
3220
|
+
"@playwright/test": "^1.0.0"
|
|
3221
|
+
},
|
|
3222
|
+
extraFiles: [
|
|
3223
|
+
{
|
|
3224
|
+
path: "playwright.config.ts",
|
|
3225
|
+
content: `import { defineConfig, devices } from '@playwright/test';
|
|
3226
|
+
|
|
3227
|
+
export default defineConfig({
|
|
3228
|
+
testDir: './e2e',
|
|
3229
|
+
fullyParallel: true,
|
|
3230
|
+
forbidOnly: !!process.env.CI,
|
|
3231
|
+
retries: process.env.CI ? 2 : 0,
|
|
3232
|
+
reporter: 'html',
|
|
3233
|
+
use: {
|
|
3234
|
+
baseURL: 'http://localhost:5173',
|
|
3235
|
+
trace: 'on-first-retry',
|
|
3236
|
+
},
|
|
3237
|
+
projects: [
|
|
3238
|
+
{
|
|
3239
|
+
name: 'chromium',
|
|
3240
|
+
use: { ...devices['Desktop Chrome'] },
|
|
3241
|
+
},
|
|
3242
|
+
],
|
|
3243
|
+
webServer: {
|
|
3244
|
+
command: 'vite',
|
|
3245
|
+
url: 'http://localhost:5173',
|
|
3246
|
+
reuseExistingServer: !process.env.CI,
|
|
3247
|
+
},
|
|
3248
|
+
});
|
|
3249
|
+
`
|
|
3250
|
+
},
|
|
3251
|
+
{
|
|
3252
|
+
path: "e2e/example.test.ts",
|
|
3253
|
+
content: `import { expect, test } from '@playwright/test';
|
|
3254
|
+
|
|
3255
|
+
test('has title', async ({ page }) => {
|
|
3256
|
+
await page.goto('/');
|
|
3257
|
+
await expect(page).toHaveTitle(/Vite/);
|
|
3258
|
+
});
|
|
3213
3259
|
`
|
|
3214
3260
|
}
|
|
3215
3261
|
]
|
|
@@ -3242,6 +3288,10 @@ function buildPackageJson(ctx) {
|
|
|
3242
3288
|
pkg.scripts["test"] = "vitest";
|
|
3243
3289
|
pkg.scripts["test:ui"] = "vitest --ui";
|
|
3244
3290
|
}
|
|
3291
|
+
if (ctx.features.includes("playwright")) {
|
|
3292
|
+
pkg.scripts["test:e2e"] = "playwright test";
|
|
3293
|
+
pkg.scripts["test:e2e:ui"] = "playwright test --ui";
|
|
3294
|
+
}
|
|
3245
3295
|
return JSON.stringify(pkg, null, 2) + `
|
|
3246
3296
|
`;
|
|
3247
3297
|
}
|
|
@@ -3409,8 +3459,8 @@ var createCommand = defineCommand({
|
|
|
3409
3459
|
// src/commands/build/index.ts
|
|
3410
3460
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
3411
3461
|
import { existsSync } from "node:fs";
|
|
3412
|
-
import { readFile as readFile2, rm, writeFile as writeFile3 } from "node:fs/promises";
|
|
3413
|
-
import { dirname as dirname3, join as join4, relative, resolve as resolve2 } from "node:path";
|
|
3462
|
+
import { readFile as readFile2, readdir as readdir2, rm, writeFile as writeFile3 } from "node:fs/promises";
|
|
3463
|
+
import { dirname as dirname3, extname, join as join4, relative, resolve as resolve2 } from "node:path";
|
|
3414
3464
|
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
3415
3465
|
function resolveViteBin(cwd) {
|
|
3416
3466
|
const local = join4(cwd, "node_modules", ".bin", "vite");
|
|
@@ -3468,6 +3518,83 @@ async function inlineAssets(distDir) {
|
|
|
3468
3518
|
});
|
|
3469
3519
|
return html;
|
|
3470
3520
|
}
|
|
3521
|
+
var MIME_MAP = {
|
|
3522
|
+
".png": "image/png",
|
|
3523
|
+
".jpg": "image/jpeg",
|
|
3524
|
+
".jpeg": "image/jpeg",
|
|
3525
|
+
".gif": "image/gif",
|
|
3526
|
+
".webp": "image/webp",
|
|
3527
|
+
".svg": "image/svg+xml",
|
|
3528
|
+
".ico": "image/x-icon",
|
|
3529
|
+
".avif": "image/avif",
|
|
3530
|
+
".pdf": "application/pdf",
|
|
3531
|
+
".woff": "font/woff",
|
|
3532
|
+
".woff2": "font/woff2",
|
|
3533
|
+
".ttf": "font/ttf",
|
|
3534
|
+
".otf": "font/otf"
|
|
3535
|
+
};
|
|
3536
|
+
function stripViteHash(filename) {
|
|
3537
|
+
return filename.replace(/-[A-Za-z0-9_-]{8,}(\.[^.]+)$/, "$1");
|
|
3538
|
+
}
|
|
3539
|
+
async function discoverAssets(distDir) {
|
|
3540
|
+
const assetsDir = join4(distDir, "assets");
|
|
3541
|
+
if (!existsSync(assetsDir))
|
|
3542
|
+
return [];
|
|
3543
|
+
const files = await readdir2(assetsDir);
|
|
3544
|
+
return files.filter((f3) => !f3.endsWith(".js") && !f3.endsWith(".css") && !f3.endsWith(".map")).map((f3) => ({
|
|
3545
|
+
assetPath: `/assets/${f3}`,
|
|
3546
|
+
diskPath: join4(assetsDir, f3),
|
|
3547
|
+
ext: extname(f3).toLowerCase(),
|
|
3548
|
+
displayName: stripViteHash(f3)
|
|
3549
|
+
}));
|
|
3550
|
+
}
|
|
3551
|
+
function findReferencedAssets(html, assets) {
|
|
3552
|
+
return assets.filter((a3) => html.includes(a3.assetPath));
|
|
3553
|
+
}
|
|
3554
|
+
async function inlineAssetsAsBase64(html, assets) {
|
|
3555
|
+
let result = html;
|
|
3556
|
+
for (const asset of assets) {
|
|
3557
|
+
const mime = MIME_MAP[asset.ext] ?? "application/octet-stream";
|
|
3558
|
+
const data = await readFile2(asset.diskPath);
|
|
3559
|
+
const dataUri = `data:${mime};base64,${data.toString("base64")}`;
|
|
3560
|
+
result = result.replaceAll(asset.assetPath, dataUri);
|
|
3561
|
+
}
|
|
3562
|
+
return result;
|
|
3563
|
+
}
|
|
3564
|
+
function applyAssetUrls(html, replacements) {
|
|
3565
|
+
let result = html;
|
|
3566
|
+
for (const [assetPath, url] of replacements) {
|
|
3567
|
+
result = result.replaceAll(assetPath, url);
|
|
3568
|
+
}
|
|
3569
|
+
return result;
|
|
3570
|
+
}
|
|
3571
|
+
async function promptAssetUrls(assets) {
|
|
3572
|
+
const replacements = new Map;
|
|
3573
|
+
for (const asset of assets) {
|
|
3574
|
+
const answer = await ue({
|
|
3575
|
+
message: `Remote URL for ${import_picocolors6.default.cyan(asset.displayName)} ${import_picocolors6.default.dim(`(${asset.assetPath})`)}:`,
|
|
3576
|
+
placeholder: `https://cdn.example.com/${asset.displayName}`,
|
|
3577
|
+
validate(value) {
|
|
3578
|
+
const v3 = value.trim();
|
|
3579
|
+
if (v3.length === 0)
|
|
3580
|
+
return;
|
|
3581
|
+
if (!v3.startsWith("http://") && !v3.startsWith("https://") && !v3.startsWith("/")) {
|
|
3582
|
+
return "Enter a valid URL (https://...) or root-relative path (/...), or leave blank to keep the original.";
|
|
3583
|
+
}
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
});
|
|
3587
|
+
if (BD(answer)) {
|
|
3588
|
+
ve2("Build cancelled.");
|
|
3589
|
+
process.exit(0);
|
|
3590
|
+
}
|
|
3591
|
+
const url = answer.trim();
|
|
3592
|
+
if (url.length > 0) {
|
|
3593
|
+
replacements.set(asset.assetPath, url);
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
return replacements;
|
|
3597
|
+
}
|
|
3471
3598
|
async function renderSSR(projectDir, appEntry, viteBin) {
|
|
3472
3599
|
const tempDir = join4(projectDir, ".svelte-bundle");
|
|
3473
3600
|
const ssrEntryPath = join4(tempDir, "entry-ssr.ts");
|
|
@@ -3545,6 +3672,11 @@ var buildCommand = defineCommand({
|
|
|
3545
3672
|
description: "Vite build mode (default: production)",
|
|
3546
3673
|
default: "production",
|
|
3547
3674
|
alias: "m"
|
|
3675
|
+
},
|
|
3676
|
+
"inline-assets": {
|
|
3677
|
+
type: "boolean",
|
|
3678
|
+
description: "Embed binary assets (images, fonts, etc.) as base64 data URIs instead of prompting for remote URLs",
|
|
3679
|
+
default: false
|
|
3548
3680
|
}
|
|
3549
3681
|
},
|
|
3550
3682
|
async run({ args }) {
|
|
@@ -3576,6 +3708,23 @@ var buildCommand = defineCommand({
|
|
|
3576
3708
|
html = injectSSRContent(html, ssrResult);
|
|
3577
3709
|
logger.success("SSR content injected.");
|
|
3578
3710
|
}
|
|
3711
|
+
const allAssets = await discoverAssets(distDir);
|
|
3712
|
+
const referencedAssets = findReferencedAssets(html, allAssets);
|
|
3713
|
+
if (referencedAssets.length > 0) {
|
|
3714
|
+
if (args["inline-assets"]) {
|
|
3715
|
+
logger.step(`Inlining ${referencedAssets.length} asset(s) as base64...`);
|
|
3716
|
+
html = await inlineAssetsAsBase64(html, referencedAssets);
|
|
3717
|
+
logger.success("Assets inlined.");
|
|
3718
|
+
} else {
|
|
3719
|
+
logger.info(`Found ${import_picocolors6.default.yellow(String(referencedAssets.length))} binary asset(s) referenced in the output.
|
|
3720
|
+
` + import_picocolors6.default.dim(" Enter a remote URL for each, or leave blank to keep the original build path."));
|
|
3721
|
+
const replacements = await promptAssetUrls(referencedAssets);
|
|
3722
|
+
if (replacements.size > 0) {
|
|
3723
|
+
html = applyAssetUrls(html, replacements);
|
|
3724
|
+
logger.success(`Updated ${replacements.size} asset URL(s).`);
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3579
3728
|
await ensureDir(dirname3(outfile));
|
|
3580
3729
|
await writeFile3(outfile, html, "utf-8");
|
|
3581
3730
|
const relOut = relative(projectDir, outfile);
|