@marko/vite 5.2.1 → 5.3.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/dist/index.d.ts +1 -0
- package/dist/index.mjs +76 -53
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -775,6 +775,7 @@ var virtualFiles = /* @__PURE__ */ new Map();
|
|
|
775
775
|
var extReg = /\.[^.]+$/;
|
|
776
776
|
var queryReg = /\?marko-[^?]+$/;
|
|
777
777
|
var importTagReg2 = /^<([^>]+)>$/;
|
|
778
|
+
var noClientAssetsRuntimeId = "\0no_client_bundles.mjs";
|
|
778
779
|
var browserEntryQuery = "?marko-browser-entry";
|
|
779
780
|
var serverEntryQuery = "?marko-server-entry";
|
|
780
781
|
var virtualFileQuery = "?marko-virtual";
|
|
@@ -830,6 +831,7 @@ function markoPlugin(opts = {}) {
|
|
|
830
831
|
let serverManifest;
|
|
831
832
|
let basePath = "/";
|
|
832
833
|
let getMarkoAssetFns;
|
|
834
|
+
let checkIsEntry = () => true;
|
|
833
835
|
const entryIds = /* @__PURE__ */ new Set();
|
|
834
836
|
const cachedSources = /* @__PURE__ */ new Map();
|
|
835
837
|
const transformWatchFiles = /* @__PURE__ */ new Map();
|
|
@@ -877,6 +879,9 @@ function markoPlugin(opts = {}) {
|
|
|
877
879
|
}
|
|
878
880
|
runtimeId = opts.runtimeId;
|
|
879
881
|
basePathVar = opts.basePathVar;
|
|
882
|
+
if (opts.isEntry) {
|
|
883
|
+
checkIsEntry = opts.isEntry;
|
|
884
|
+
}
|
|
880
885
|
if ("BASE_URL" in process.env && config.base == null) {
|
|
881
886
|
config.base = process.env.BASE_URL;
|
|
882
887
|
}
|
|
@@ -1106,22 +1111,35 @@ function markoPlugin(opts = {}) {
|
|
|
1106
1111
|
}
|
|
1107
1112
|
},
|
|
1108
1113
|
async options(inputOptions) {
|
|
1109
|
-
if (
|
|
1110
|
-
|
|
1111
|
-
serverManifest =
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1114
|
+
if (linked && isBuild) {
|
|
1115
|
+
if (isSSRBuild) {
|
|
1116
|
+
serverManifest = {
|
|
1117
|
+
entries: {},
|
|
1118
|
+
entrySources: {},
|
|
1119
|
+
chunksNeedingAssets: [],
|
|
1120
|
+
ssrAssetIds: []
|
|
1121
|
+
};
|
|
1122
|
+
} else {
|
|
1123
|
+
try {
|
|
1124
|
+
serverManifest = await store.read();
|
|
1125
|
+
if (isEmpty(serverManifest.entries)) {
|
|
1126
|
+
inputOptions.input = noClientAssetsRuntimeId;
|
|
1127
|
+
} else {
|
|
1128
|
+
inputOptions.input = toHTMLEntries(
|
|
1129
|
+
root,
|
|
1130
|
+
serverManifest.entries
|
|
1131
|
+
);
|
|
1132
|
+
for (const entry in serverManifest.entrySources) {
|
|
1133
|
+
const id = normalizePath(path6.resolve(root, entry));
|
|
1134
|
+
entryIds.add(id);
|
|
1135
|
+
cachedSources.set(id, serverManifest.entrySources[entry]);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
} catch (err) {
|
|
1139
|
+
this.error(
|
|
1140
|
+
`You must run the "ssr" build before the "browser" build.`
|
|
1141
|
+
);
|
|
1117
1142
|
}
|
|
1118
|
-
} catch (err) {
|
|
1119
|
-
this.error(
|
|
1120
|
-
`You must run the "ssr" build before the "browser" build.`
|
|
1121
|
-
);
|
|
1122
|
-
}
|
|
1123
|
-
if (isEmpty(inputOptions.input)) {
|
|
1124
|
-
this.error("No Marko files were found when compiling the server.");
|
|
1125
1143
|
}
|
|
1126
1144
|
}
|
|
1127
1145
|
},
|
|
@@ -1139,8 +1157,8 @@ function markoPlugin(opts = {}) {
|
|
|
1139
1157
|
if (virtualFiles.has(importee)) {
|
|
1140
1158
|
return importee;
|
|
1141
1159
|
}
|
|
1142
|
-
if (importee === renderAssetsRuntimeId) {
|
|
1143
|
-
return { id:
|
|
1160
|
+
if (importee === renderAssetsRuntimeId || importee === noClientAssetsRuntimeId) {
|
|
1161
|
+
return { id: importee };
|
|
1144
1162
|
}
|
|
1145
1163
|
if (importer) {
|
|
1146
1164
|
const tagName = importTagReg2.exec(importee)?.[1];
|
|
@@ -1154,7 +1172,10 @@ function markoPlugin(opts = {}) {
|
|
|
1154
1172
|
importee = importee.slice(0, -importeeQuery.length);
|
|
1155
1173
|
} else if (!importOpts.scan) {
|
|
1156
1174
|
if (ssr && linked && importer && importer[0] !== "\0" && (importer !== devEntryFile || normalizePath(importer) !== devEntryFilePosix) && // Vite tries to resolve against an `index.html` in some cases, we ignore it here.
|
|
1157
|
-
isMarkoFile(importee) && !isMarkoFile(importer
|
|
1175
|
+
isMarkoFile(importee) && !queryReg.test(importer) && !isMarkoFile(importer) && checkIsEntry(
|
|
1176
|
+
normalizePath(path6.resolve(importer, "..", importee)),
|
|
1177
|
+
importer
|
|
1178
|
+
)) {
|
|
1158
1179
|
importeeQuery = serverEntryQuery;
|
|
1159
1180
|
} else if (!ssr && isBuild && importer && isMarkoFile(importee) && this.getModuleInfo(importer)?.isEntry) {
|
|
1160
1181
|
importeeQuery = browserEntryQuery;
|
|
@@ -1193,6 +1214,9 @@ function markoPlugin(opts = {}) {
|
|
|
1193
1214
|
if (id === renderAssetsRuntimeId) {
|
|
1194
1215
|
return renderAssetsRuntimeCode;
|
|
1195
1216
|
}
|
|
1217
|
+
if (id === noClientAssetsRuntimeId) {
|
|
1218
|
+
return "NO_CLIENT_ASSETS";
|
|
1219
|
+
}
|
|
1196
1220
|
const query = getMarkoQuery(id);
|
|
1197
1221
|
switch (query) {
|
|
1198
1222
|
case serverEntryQuery: {
|
|
@@ -1228,12 +1252,6 @@ function markoPlugin(opts = {}) {
|
|
|
1228
1252
|
path6.relative(root, fileName)
|
|
1229
1253
|
);
|
|
1230
1254
|
const entryId = toEntryId(relativeFileName);
|
|
1231
|
-
serverManifest ??= {
|
|
1232
|
-
entries: {},
|
|
1233
|
-
entrySources: {},
|
|
1234
|
-
chunksNeedingAssets: [],
|
|
1235
|
-
ssrAssetIds: []
|
|
1236
|
-
};
|
|
1237
1255
|
serverManifest.entries[entryId] = relativeFileName;
|
|
1238
1256
|
serverManifest.entrySources[relativeFileName] = source;
|
|
1239
1257
|
mainEntryData = JSON.stringify(entryId);
|
|
@@ -1366,11 +1384,6 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
|
1366
1384
|
`Linked builds are currently only supported when in "write" mode.`
|
|
1367
1385
|
);
|
|
1368
1386
|
}
|
|
1369
|
-
if (!serverManifest) {
|
|
1370
|
-
this.error(
|
|
1371
|
-
"No Marko files were found when bundling the server in linked mode."
|
|
1372
|
-
);
|
|
1373
|
-
}
|
|
1374
1387
|
if (isSSRBuild) {
|
|
1375
1388
|
const dir = outputOptions.dir ? path6.resolve(outputOptions.dir) : path6.resolve(outputOptions.file, "..");
|
|
1376
1389
|
for (const fileName in bundle) {
|
|
@@ -1397,32 +1410,42 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
|
1397
1410
|
store.write(serverManifest);
|
|
1398
1411
|
} else {
|
|
1399
1412
|
const browserManifest = {};
|
|
1400
|
-
|
|
1401
|
-
const
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
basePath,
|
|
1408
|
-
chunk.source.toString()
|
|
1409
|
-
),
|
|
1410
|
-
preload: void 0
|
|
1411
|
-
// clear out preload for prod builds.
|
|
1412
|
-
};
|
|
1413
|
-
delete bundle[chunkId];
|
|
1414
|
-
} else {
|
|
1415
|
-
this.error(
|
|
1416
|
-
`Marko template had unexpected output from vite, ${fileName}`
|
|
1417
|
-
);
|
|
1413
|
+
if (isEmpty(serverManifest.entries)) {
|
|
1414
|
+
for (const chunkId in bundle) {
|
|
1415
|
+
const chunk = bundle[chunkId];
|
|
1416
|
+
if (chunk.type === "chunk" && chunk.facadeModuleId === noClientAssetsRuntimeId) {
|
|
1417
|
+
delete bundle[chunkId];
|
|
1418
|
+
delete bundle[chunkId + ".map"];
|
|
1419
|
+
}
|
|
1418
1420
|
}
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1421
|
+
} else {
|
|
1422
|
+
for (const entryId in serverManifest.entries) {
|
|
1423
|
+
const fileName = serverManifest.entries[entryId];
|
|
1424
|
+
const chunkId = fileName + htmlExt;
|
|
1425
|
+
const chunk = bundle[chunkId];
|
|
1426
|
+
if (chunk?.type === "asset") {
|
|
1427
|
+
browserManifest[entryId] = {
|
|
1428
|
+
...await generateDocManifest(
|
|
1429
|
+
basePath,
|
|
1430
|
+
chunk.source.toString()
|
|
1431
|
+
),
|
|
1432
|
+
preload: void 0
|
|
1433
|
+
// clear out preload for prod builds.
|
|
1434
|
+
};
|
|
1435
|
+
delete bundle[chunkId];
|
|
1436
|
+
} else {
|
|
1437
|
+
this.error(
|
|
1438
|
+
`Marko template had unexpected output from vite, ${fileName}`
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
|
|
1443
|
+
browserManifest
|
|
1444
|
+
)};
|
|
1423
1445
|
`;
|
|
1424
|
-
|
|
1425
|
-
|
|
1446
|
+
for (const fileName of serverManifest.chunksNeedingAssets) {
|
|
1447
|
+
await fs4.promises.appendFile(fileName, manifestStr);
|
|
1448
|
+
}
|
|
1426
1449
|
}
|
|
1427
1450
|
}
|
|
1428
1451
|
}
|