wxt 0.1.2 → 0.1.4
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 +4 -4
- package/dist/cli.cjs +72 -54
- package/dist/index.cjs +71 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +74 -56
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// src/core/utils/getInternalConfig.ts
|
|
2
2
|
import path2, { resolve as resolve6 } from "node:path";
|
|
3
|
-
import * as vite2 from "vite";
|
|
4
|
-
import { consola } from "consola";
|
|
5
|
-
|
|
6
|
-
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
7
3
|
import * as vite from "vite";
|
|
4
|
+
import { consola } from "consola";
|
|
8
5
|
|
|
9
6
|
// src/core/utils/entrypoints.ts
|
|
10
7
|
import path, { relative, resolve } from "node:path";
|
|
@@ -27,20 +24,17 @@ function devHtmlPrerender(config) {
|
|
|
27
24
|
return {
|
|
28
25
|
apply: "build",
|
|
29
26
|
name: "wxt:dev-html-prerender",
|
|
30
|
-
config(
|
|
31
|
-
return
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
)
|
|
39
|
-
}
|
|
27
|
+
config() {
|
|
28
|
+
return {
|
|
29
|
+
resolve: {
|
|
30
|
+
alias: {
|
|
31
|
+
"@wxt/reload-html": resolve2(
|
|
32
|
+
config.root,
|
|
33
|
+
"node_modules/wxt/dist/virtual-modules/reload-html.js"
|
|
34
|
+
)
|
|
40
35
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
44
38
|
},
|
|
45
39
|
async transform(html, id) {
|
|
46
40
|
const server = config.server;
|
|
@@ -88,17 +82,18 @@ function devHtmlPrerender(config) {
|
|
|
88
82
|
function devServerGlobals(internalConfig) {
|
|
89
83
|
return {
|
|
90
84
|
name: "wxt:dev-server-globals",
|
|
91
|
-
config(
|
|
85
|
+
config() {
|
|
92
86
|
if (internalConfig.server == null || internalConfig.command == "build")
|
|
93
87
|
return;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
return {
|
|
89
|
+
define: {
|
|
90
|
+
__DEV_SERVER_PROTOCOL__: JSON.stringify("ws:"),
|
|
91
|
+
__DEV_SERVER_HOSTNAME__: JSON.stringify(
|
|
92
|
+
internalConfig.server.hostname
|
|
93
|
+
),
|
|
94
|
+
__DEV_SERVER_PORT__: JSON.stringify(internalConfig.server.port)
|
|
95
|
+
}
|
|
96
|
+
};
|
|
102
97
|
}
|
|
103
98
|
};
|
|
104
99
|
}
|
|
@@ -218,7 +213,7 @@ function multipageMove(entrypoints, config) {
|
|
|
218
213
|
import { createUnimport } from "unimport";
|
|
219
214
|
|
|
220
215
|
// src/core/utils/auto-imports.ts
|
|
221
|
-
import { mergeConfig
|
|
216
|
+
import { mergeConfig } from "vite";
|
|
222
217
|
function getUnimportOptions(config) {
|
|
223
218
|
const defaultOptions = {
|
|
224
219
|
debugLog: config.logger.debug,
|
|
@@ -230,7 +225,7 @@ function getUnimportOptions(config) {
|
|
|
230
225
|
warn: config.logger.warn,
|
|
231
226
|
dirs: ["components", "composables", "hooks", "utils"]
|
|
232
227
|
};
|
|
233
|
-
return
|
|
228
|
+
return mergeConfig(
|
|
234
229
|
defaultOptions,
|
|
235
230
|
config.imports
|
|
236
231
|
);
|
|
@@ -371,12 +366,6 @@ async function getInternalConfig(config, command) {
|
|
|
371
366
|
const outBaseDir = path2.resolve(root, ".output");
|
|
372
367
|
const outDir = path2.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
373
368
|
const logger = config.logger ?? consola;
|
|
374
|
-
const manifest = await (typeof config.manifest === "function" ? config.manifest({
|
|
375
|
-
browser,
|
|
376
|
-
command,
|
|
377
|
-
manifestVersion,
|
|
378
|
-
mode
|
|
379
|
-
}) : config.manifest ?? {});
|
|
380
369
|
const baseConfig = {
|
|
381
370
|
root,
|
|
382
371
|
outDir,
|
|
@@ -388,7 +377,6 @@ async function getInternalConfig(config, command) {
|
|
|
388
377
|
command,
|
|
389
378
|
logger,
|
|
390
379
|
vite: config.vite ?? {},
|
|
391
|
-
manifest,
|
|
392
380
|
imports: config.imports ?? {},
|
|
393
381
|
runnerConfig: await loadConfig({
|
|
394
382
|
name: "web-ext",
|
|
@@ -409,7 +397,7 @@ async function getInternalConfig(config, command) {
|
|
|
409
397
|
});
|
|
410
398
|
userConfig = loaded.config ?? {};
|
|
411
399
|
}
|
|
412
|
-
const merged =
|
|
400
|
+
const merged = vite.mergeConfig(
|
|
413
401
|
baseConfig,
|
|
414
402
|
userConfig
|
|
415
403
|
);
|
|
@@ -421,6 +409,10 @@ async function getInternalConfig(config, command) {
|
|
|
421
409
|
const publicDir = resolve6(srcDir, userConfig.publicDir ?? "public");
|
|
422
410
|
const wxtDir = resolve6(srcDir, ".wxt");
|
|
423
411
|
const typesDir = resolve6(wxtDir, "types");
|
|
412
|
+
const env = { mode, browser, manifestVersion, command };
|
|
413
|
+
const userManifest = await resolveManifestConfig(env, userConfig.manifest);
|
|
414
|
+
const inlineManifest = await resolveManifestConfig(env, config.manifest);
|
|
415
|
+
const manifest = vite.mergeConfig(userManifest, inlineManifest);
|
|
424
416
|
const finalConfig = {
|
|
425
417
|
...merged,
|
|
426
418
|
srcDir,
|
|
@@ -428,7 +420,8 @@ async function getInternalConfig(config, command) {
|
|
|
428
420
|
publicDir,
|
|
429
421
|
wxtDir,
|
|
430
422
|
typesDir,
|
|
431
|
-
fsCache: createFsCache(wxtDir)
|
|
423
|
+
fsCache: createFsCache(wxtDir),
|
|
424
|
+
manifest
|
|
432
425
|
};
|
|
433
426
|
finalConfig.vite.root = root;
|
|
434
427
|
finalConfig.vite.configFile = false;
|
|
@@ -453,10 +446,13 @@ async function getInternalConfig(config, command) {
|
|
|
453
446
|
});
|
|
454
447
|
return finalConfig;
|
|
455
448
|
}
|
|
449
|
+
async function resolveManifestConfig(env, manifest) {
|
|
450
|
+
return await (typeof manifest === "function" ? manifest(env) : manifest ?? {});
|
|
451
|
+
}
|
|
456
452
|
|
|
457
453
|
// src/index.ts
|
|
458
454
|
import pc3 from "picocolors";
|
|
459
|
-
import * as
|
|
455
|
+
import * as vite5 from "vite";
|
|
460
456
|
|
|
461
457
|
// src/core/utils/arrays.ts
|
|
462
458
|
function every(array, predicate) {
|
|
@@ -555,7 +551,7 @@ import { consola as consola2 } from "consola";
|
|
|
555
551
|
import { relative as relative6 } from "node:path";
|
|
556
552
|
|
|
557
553
|
// src/core/build/buildEntrypoints.ts
|
|
558
|
-
import * as
|
|
554
|
+
import * as vite2 from "vite";
|
|
559
555
|
|
|
560
556
|
// src/core/utils/removeEmptyDirs.ts
|
|
561
557
|
import fs4 from "fs-extra";
|
|
@@ -617,11 +613,11 @@ async function buildSingleEntrypoint(entrypoint, config) {
|
|
|
617
613
|
}
|
|
618
614
|
}
|
|
619
615
|
};
|
|
620
|
-
const entryConfig =
|
|
616
|
+
const entryConfig = vite2.mergeConfig(
|
|
621
617
|
libMode,
|
|
622
618
|
config.vite
|
|
623
619
|
);
|
|
624
|
-
const result = await
|
|
620
|
+
const result = await vite2.build(entryConfig);
|
|
625
621
|
return {
|
|
626
622
|
entrypoints: entrypoint,
|
|
627
623
|
chunks: getBuildOutputChunks(result)
|
|
@@ -647,11 +643,11 @@ async function buildMultipleEntrypoints(entrypoints, config) {
|
|
|
647
643
|
}
|
|
648
644
|
}
|
|
649
645
|
};
|
|
650
|
-
const entryConfig =
|
|
646
|
+
const entryConfig = vite2.mergeConfig(
|
|
651
647
|
multiPage,
|
|
652
648
|
config.vite
|
|
653
649
|
);
|
|
654
|
-
const result = await
|
|
650
|
+
const result = await vite2.build(entryConfig);
|
|
655
651
|
return {
|
|
656
652
|
entrypoints,
|
|
657
653
|
chunks: getBuildOutputChunks(result)
|
|
@@ -1015,7 +1011,20 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1015
1011
|
"strict": true,
|
|
1016
1012
|
|
|
1017
1013
|
/* Completeness */
|
|
1018
|
-
"skipLibCheck": true
|
|
1014
|
+
"skipLibCheck": true,
|
|
1015
|
+
|
|
1016
|
+
/* Aliases */
|
|
1017
|
+
"baseUrl": "${relative4(dir, config.root)}",
|
|
1018
|
+
"paths": {
|
|
1019
|
+
"@@": ["."],
|
|
1020
|
+
"@@/*": ["./*"],
|
|
1021
|
+
"~~": ["."],
|
|
1022
|
+
"~~/*": ["./*"],
|
|
1023
|
+
"@": ["${relative4(config.root, config.srcDir)}"],
|
|
1024
|
+
"@/*": ["${relative4(config.root, config.srcDir)}/*"],
|
|
1025
|
+
"~": ["${relative4(config.root, config.srcDir)}"],
|
|
1026
|
+
"~/*": ["${relative4(config.root, config.srcDir)}/*"]
|
|
1027
|
+
}
|
|
1019
1028
|
},
|
|
1020
1029
|
"include": [
|
|
1021
1030
|
"${relative4(dir, config.root)}/**/*",
|
|
@@ -1354,7 +1363,7 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1354
1363
|
|
|
1355
1364
|
// src/core/build.ts
|
|
1356
1365
|
import pc2 from "picocolors";
|
|
1357
|
-
import * as
|
|
1366
|
+
import * as vite3 from "vite";
|
|
1358
1367
|
import fs11 from "fs-extra";
|
|
1359
1368
|
|
|
1360
1369
|
// src/core/utils/groupEntrypoints.ts
|
|
@@ -1403,7 +1412,7 @@ function formatDuration(duration) {
|
|
|
1403
1412
|
}
|
|
1404
1413
|
|
|
1405
1414
|
// src/core/log/printBuildSummary.ts
|
|
1406
|
-
import path4, {
|
|
1415
|
+
import path4, { relative as relative5, resolve as resolve12 } from "path";
|
|
1407
1416
|
|
|
1408
1417
|
// src/core/log/printTable.ts
|
|
1409
1418
|
function printTable(log, rows, gap = 2) {
|
|
@@ -1440,8 +1449,8 @@ async function printBuildSummary(output, config) {
|
|
|
1440
1449
|
...output.steps.flatMap((step) => step.chunks),
|
|
1441
1450
|
...output.publicAssets
|
|
1442
1451
|
].sort((l, r) => {
|
|
1443
|
-
const lWeight =
|
|
1444
|
-
const rWeight =
|
|
1452
|
+
const lWeight = getChunkSortWeight(l.fileName);
|
|
1453
|
+
const rWeight = getChunkSortWeight(r.fileName);
|
|
1445
1454
|
const diff = lWeight - rWeight;
|
|
1446
1455
|
if (diff !== 0)
|
|
1447
1456
|
return diff;
|
|
@@ -1454,9 +1463,8 @@ async function printBuildSummary(output, config) {
|
|
|
1454
1463
|
relative5(process.cwd(), config.outDir) + path4.sep,
|
|
1455
1464
|
chunk.fileName
|
|
1456
1465
|
];
|
|
1457
|
-
const ext = extname3(chunk.fileName);
|
|
1458
1466
|
const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1459
|
-
const color =
|
|
1467
|
+
const color = getChunkColor(chunk.fileName);
|
|
1460
1468
|
const stats = await fs10.lstat(resolve12(config.outDir, chunk.fileName));
|
|
1461
1469
|
totalSize += stats.size;
|
|
1462
1470
|
const size = String(filesize(stats.size));
|
|
@@ -1475,15 +1483,25 @@ var DEFAULT_SORT_WEIGHT = 100;
|
|
|
1475
1483
|
var CHUNK_SORT_WEIGHTS = {
|
|
1476
1484
|
"manifest.json": 0,
|
|
1477
1485
|
".html": 1,
|
|
1486
|
+
".js.map": 2,
|
|
1478
1487
|
".js": 2,
|
|
1479
1488
|
".css": 3
|
|
1480
1489
|
};
|
|
1490
|
+
function getChunkSortWeight(filename) {
|
|
1491
|
+
return Object.entries(CHUNK_SORT_WEIGHTS).find(
|
|
1492
|
+
([key]) => filename.endsWith(key)
|
|
1493
|
+
)?.[1] ?? DEFAULT_SORT_WEIGHT;
|
|
1494
|
+
}
|
|
1481
1495
|
var DEFAULT_COLOR = pc.blue;
|
|
1482
1496
|
var CHUNK_COLORS = {
|
|
1497
|
+
".js.map": pc.gray,
|
|
1483
1498
|
".html": pc.green,
|
|
1484
1499
|
".css": pc.magenta,
|
|
1485
1500
|
".js": pc.cyan
|
|
1486
1501
|
};
|
|
1502
|
+
function getChunkColor(filename) {
|
|
1503
|
+
return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR;
|
|
1504
|
+
}
|
|
1487
1505
|
|
|
1488
1506
|
// src/core/build.ts
|
|
1489
1507
|
async function buildInternal(config) {
|
|
@@ -1491,7 +1509,7 @@ async function buildInternal(config) {
|
|
|
1491
1509
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
1492
1510
|
config.logger.info(
|
|
1493
1511
|
`${verb} ${pc2.cyan(target)} for ${pc2.cyan(config.mode)} with ${pc2.green(
|
|
1494
|
-
`Vite ${
|
|
1512
|
+
`Vite ${vite3.version}`
|
|
1495
1513
|
)}`
|
|
1496
1514
|
);
|
|
1497
1515
|
const startTime = Date.now();
|
|
@@ -1541,7 +1559,7 @@ async function rebuild(config, entrypointGroups, existingOutput = {
|
|
|
1541
1559
|
}
|
|
1542
1560
|
|
|
1543
1561
|
// src/core/server.ts
|
|
1544
|
-
import * as
|
|
1562
|
+
import * as vite4 from "vite";
|
|
1545
1563
|
|
|
1546
1564
|
// src/core/utils/findOpenPort.ts
|
|
1547
1565
|
import net from "node:net";
|
|
@@ -1642,8 +1660,8 @@ async function getServerInfo() {
|
|
|
1642
1660
|
}
|
|
1643
1661
|
async function setupServer(serverInfo, config) {
|
|
1644
1662
|
const runner = createWebExtRunner();
|
|
1645
|
-
const viteServer = await
|
|
1646
|
-
|
|
1663
|
+
const viteServer = await vite4.createServer(
|
|
1664
|
+
vite4.mergeConfig(serverInfo, config.vite)
|
|
1647
1665
|
);
|
|
1648
1666
|
const start = async () => {
|
|
1649
1667
|
await viteServer.listen(server.port);
|
|
@@ -1709,7 +1727,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1709
1727
|
}
|
|
1710
1728
|
|
|
1711
1729
|
// package.json
|
|
1712
|
-
var version2 = "0.1.
|
|
1730
|
+
var version2 = "0.1.4";
|
|
1713
1731
|
|
|
1714
1732
|
// src/core/utils/defineConfig.ts
|
|
1715
1733
|
function defineConfig(config) {
|
|
@@ -1729,7 +1747,7 @@ async function build2(config) {
|
|
|
1729
1747
|
async function createServer2(config) {
|
|
1730
1748
|
const serverInfo = await getServerInfo();
|
|
1731
1749
|
const getLatestInternalConfig = () => {
|
|
1732
|
-
const viteConfig =
|
|
1750
|
+
const viteConfig = vite5.mergeConfig(
|
|
1733
1751
|
serverInfo.viteServerConfig,
|
|
1734
1752
|
config?.vite ?? {}
|
|
1735
1753
|
);
|