@marko/vite 5.2.1 → 5.3.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.
Files changed (2) hide show
  1. package/dist/index.mjs +68 -52
  2. package/package.json +1 -1
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";
@@ -1106,22 +1107,35 @@ function markoPlugin(opts = {}) {
1106
1107
  }
1107
1108
  },
1108
1109
  async options(inputOptions) {
1109
- if (isBuild && linked && !isSSRBuild) {
1110
- try {
1111
- serverManifest = await store.read();
1112
- inputOptions.input = toHTMLEntries(root, serverManifest.entries);
1113
- for (const entry in serverManifest.entrySources) {
1114
- const id = normalizePath(path6.resolve(root, entry));
1115
- entryIds.add(id);
1116
- cachedSources.set(id, serverManifest.entrySources[entry]);
1110
+ if (linked && isBuild) {
1111
+ if (isSSRBuild) {
1112
+ serverManifest = {
1113
+ entries: {},
1114
+ entrySources: {},
1115
+ chunksNeedingAssets: [],
1116
+ ssrAssetIds: []
1117
+ };
1118
+ } else {
1119
+ try {
1120
+ serverManifest = await store.read();
1121
+ if (isEmpty(serverManifest.entries)) {
1122
+ inputOptions.input = noClientAssetsRuntimeId;
1123
+ } else {
1124
+ inputOptions.input = toHTMLEntries(
1125
+ root,
1126
+ serverManifest.entries
1127
+ );
1128
+ for (const entry in serverManifest.entrySources) {
1129
+ const id = normalizePath(path6.resolve(root, entry));
1130
+ entryIds.add(id);
1131
+ cachedSources.set(id, serverManifest.entrySources[entry]);
1132
+ }
1133
+ }
1134
+ } catch (err) {
1135
+ this.error(
1136
+ `You must run the "ssr" build before the "browser" build.`
1137
+ );
1117
1138
  }
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
1139
  }
1126
1140
  }
1127
1141
  },
@@ -1139,8 +1153,8 @@ function markoPlugin(opts = {}) {
1139
1153
  if (virtualFiles.has(importee)) {
1140
1154
  return importee;
1141
1155
  }
1142
- if (importee === renderAssetsRuntimeId) {
1143
- return { id: renderAssetsRuntimeId };
1156
+ if (importee === renderAssetsRuntimeId || importee === noClientAssetsRuntimeId) {
1157
+ return { id: importee };
1144
1158
  }
1145
1159
  if (importer) {
1146
1160
  const tagName = importTagReg2.exec(importee)?.[1];
@@ -1193,6 +1207,9 @@ function markoPlugin(opts = {}) {
1193
1207
  if (id === renderAssetsRuntimeId) {
1194
1208
  return renderAssetsRuntimeCode;
1195
1209
  }
1210
+ if (id === noClientAssetsRuntimeId) {
1211
+ return "NO_CLIENT_ASSETS";
1212
+ }
1196
1213
  const query = getMarkoQuery(id);
1197
1214
  switch (query) {
1198
1215
  case serverEntryQuery: {
@@ -1228,12 +1245,6 @@ function markoPlugin(opts = {}) {
1228
1245
  path6.relative(root, fileName)
1229
1246
  );
1230
1247
  const entryId = toEntryId(relativeFileName);
1231
- serverManifest ??= {
1232
- entries: {},
1233
- entrySources: {},
1234
- chunksNeedingAssets: [],
1235
- ssrAssetIds: []
1236
- };
1237
1248
  serverManifest.entries[entryId] = relativeFileName;
1238
1249
  serverManifest.entrySources[relativeFileName] = source;
1239
1250
  mainEntryData = JSON.stringify(entryId);
@@ -1366,11 +1377,6 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
1366
1377
  `Linked builds are currently only supported when in "write" mode.`
1367
1378
  );
1368
1379
  }
1369
- if (!serverManifest) {
1370
- this.error(
1371
- "No Marko files were found when bundling the server in linked mode."
1372
- );
1373
- }
1374
1380
  if (isSSRBuild) {
1375
1381
  const dir = outputOptions.dir ? path6.resolve(outputOptions.dir) : path6.resolve(outputOptions.file, "..");
1376
1382
  for (const fileName in bundle) {
@@ -1397,32 +1403,42 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
1397
1403
  store.write(serverManifest);
1398
1404
  } else {
1399
1405
  const browserManifest = {};
1400
- for (const entryId in serverManifest.entries) {
1401
- const fileName = serverManifest.entries[entryId];
1402
- const chunkId = fileName + htmlExt;
1403
- const chunk = bundle[chunkId];
1404
- if (chunk?.type === "asset") {
1405
- browserManifest[entryId] = {
1406
- ...await generateDocManifest(
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
- );
1406
+ if (isEmpty(serverManifest.entries)) {
1407
+ for (const chunkId in bundle) {
1408
+ const chunk = bundle[chunkId];
1409
+ if (chunk.type === "chunk" && chunk.facadeModuleId === noClientAssetsRuntimeId) {
1410
+ delete bundle[chunkId];
1411
+ delete bundle[chunkId + ".map"];
1412
+ }
1418
1413
  }
1419
- }
1420
- const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
1421
- browserManifest
1422
- )};
1414
+ } else {
1415
+ for (const entryId in serverManifest.entries) {
1416
+ const fileName = serverManifest.entries[entryId];
1417
+ const chunkId = fileName + htmlExt;
1418
+ const chunk = bundle[chunkId];
1419
+ if (chunk?.type === "asset") {
1420
+ browserManifest[entryId] = {
1421
+ ...await generateDocManifest(
1422
+ basePath,
1423
+ chunk.source.toString()
1424
+ ),
1425
+ preload: void 0
1426
+ // clear out preload for prod builds.
1427
+ };
1428
+ delete bundle[chunkId];
1429
+ } else {
1430
+ this.error(
1431
+ `Marko template had unexpected output from vite, ${fileName}`
1432
+ );
1433
+ }
1434
+ }
1435
+ const manifestStr = `;var __MARKO_MANIFEST__=${JSON.stringify(
1436
+ browserManifest
1437
+ )};
1423
1438
  `;
1424
- for (const fileName of serverManifest.chunksNeedingAssets) {
1425
- await fs4.promises.appendFile(fileName, manifestStr);
1439
+ for (const fileName of serverManifest.chunksNeedingAssets) {
1440
+ await fs4.promises.appendFile(fileName, manifestStr);
1441
+ }
1426
1442
  }
1427
1443
  }
1428
1444
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
- "version": "5.2.1",
3
+ "version": "5.3.0",
4
4
  "description": "A Marko plugin for Vite",
5
5
  "keywords": [
6
6
  "loader",