@marko/vite 5.3.9 → 5.4.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/index.mjs +59 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -887,6 +887,20 @@ function markoPlugin(opts = {}) {
|
|
|
887
887
|
name: "marko-vite:pre",
|
|
888
888
|
enforce: "pre",
|
|
889
889
|
// Must be pre to allow us to resolve assets before vite.
|
|
890
|
+
sharedDuringBuild: true,
|
|
891
|
+
async buildApp(builder) {
|
|
892
|
+
const { ssr, client } = builder.environments;
|
|
893
|
+
if (!ssr || !client) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
if (builder.config?.builder?.buildApp) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
if (linked) {
|
|
900
|
+
await builder.build(ssr);
|
|
901
|
+
}
|
|
902
|
+
await builder.build(client);
|
|
903
|
+
},
|
|
890
904
|
async config(config, env) {
|
|
891
905
|
let optimize = env.mode === "production";
|
|
892
906
|
isTest = env.mode === "test";
|
|
@@ -1049,6 +1063,10 @@ function markoPlugin(opts = {}) {
|
|
|
1049
1063
|
config.build.commonjsOptions ??= {};
|
|
1050
1064
|
config.build.commonjsOptions.esmExternals = (id) => !isCJSModule(id, rootResolveFile);
|
|
1051
1065
|
}
|
|
1066
|
+
if (linked && !isSSRBuild) {
|
|
1067
|
+
config.build ??= {};
|
|
1068
|
+
config.build.emptyOutDir = false;
|
|
1069
|
+
}
|
|
1052
1070
|
if (basePathVar) {
|
|
1053
1071
|
config.experimental ??= {};
|
|
1054
1072
|
if (config.experimental.renderBuiltUrl) {
|
|
@@ -1093,6 +1111,42 @@ function markoPlugin(opts = {}) {
|
|
|
1093
1111
|
}
|
|
1094
1112
|
};
|
|
1095
1113
|
},
|
|
1114
|
+
configEnvironment(name, options) {
|
|
1115
|
+
if (name === "ssr") {
|
|
1116
|
+
options.resolve ??= {};
|
|
1117
|
+
const { noExternal } = options.resolve;
|
|
1118
|
+
if (noExternal !== true) {
|
|
1119
|
+
const noExternalReg = /\.marko$/;
|
|
1120
|
+
if (noExternal) {
|
|
1121
|
+
if (Array.isArray(noExternal)) {
|
|
1122
|
+
options.resolve.noExternal = [...noExternal, noExternalReg];
|
|
1123
|
+
} else {
|
|
1124
|
+
options.resolve.noExternal = [noExternal, noExternalReg];
|
|
1125
|
+
}
|
|
1126
|
+
} else {
|
|
1127
|
+
options.resolve.noExternal = noExternalReg;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
options.build ??= {};
|
|
1131
|
+
options.build.emptyOutDir = true;
|
|
1132
|
+
if (!options.build?.rollupOptions?.output) {
|
|
1133
|
+
options.build.rollupOptions ??= {};
|
|
1134
|
+
options.build.rollupOptions.output = {
|
|
1135
|
+
chunkFileNames: `[name]-[hash].js`
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
if (!options.build?.commonjsOptions?.esmExternals) {
|
|
1139
|
+
options.build.commonjsOptions ??= {};
|
|
1140
|
+
options.build.commonjsOptions.esmExternals = (id) => !isCJSModule(id, rootResolveFile);
|
|
1141
|
+
}
|
|
1142
|
+
} else {
|
|
1143
|
+
if (linked) {
|
|
1144
|
+
options.build ??= {};
|
|
1145
|
+
options.build.emptyOutDir = false;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
return options;
|
|
1149
|
+
},
|
|
1096
1150
|
configResolved(config) {
|
|
1097
1151
|
basePath = config.base;
|
|
1098
1152
|
cacheDir = config.cacheDir && normalizePath(config.cacheDir);
|
|
@@ -1150,7 +1204,7 @@ function markoPlugin(opts = {}) {
|
|
|
1150
1204
|
},
|
|
1151
1205
|
async options(inputOptions) {
|
|
1152
1206
|
if (linked && isBuild) {
|
|
1153
|
-
if (isSSRBuild) {
|
|
1207
|
+
if (isSSRBuild || this.environment?.name === "ssr") {
|
|
1154
1208
|
serverManifest = {
|
|
1155
1209
|
entries: {},
|
|
1156
1210
|
entrySources: {},
|
|
@@ -1182,7 +1236,7 @@ function markoPlugin(opts = {}) {
|
|
|
1182
1236
|
}
|
|
1183
1237
|
},
|
|
1184
1238
|
async buildStart() {
|
|
1185
|
-
if (isBuild && linked && !isSSRBuild) {
|
|
1239
|
+
if (isBuild && linked && !isSSRBuild && this.environment?.name !== "ssr") {
|
|
1186
1240
|
for (const assetId of serverManifest.ssrAssetIds) {
|
|
1187
1241
|
this.load({
|
|
1188
1242
|
id: normalizePath(path6.resolve(root, assetId)),
|
|
@@ -1426,7 +1480,8 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
|
1426
1480
|
name: "marko-vite:post",
|
|
1427
1481
|
apply: "build",
|
|
1428
1482
|
enforce: "post",
|
|
1429
|
-
// We use a "post" plugin to allow us to read the final generated `.html` from vite
|
|
1483
|
+
// We use a "post" plugin to allow us to read the final generated `.html` from vite.,
|
|
1484
|
+
sharedDuringBuild: true,
|
|
1430
1485
|
transform(_source, id, opts2) {
|
|
1431
1486
|
if (!opts2?.ssr && /\.module\.[^.]+(?:\?|$)/.test(id)) {
|
|
1432
1487
|
return {
|
|
@@ -1443,7 +1498,7 @@ if (import.meta.hot) import.meta.hot.accept(() => {});`;
|
|
|
1443
1498
|
`Linked builds are currently only supported when in "write" mode.`
|
|
1444
1499
|
);
|
|
1445
1500
|
}
|
|
1446
|
-
if (isSSRBuild) {
|
|
1501
|
+
if (isSSRBuild || this.environment?.name === "ssr") {
|
|
1447
1502
|
const dir = outputOptions.dir ? path6.resolve(outputOptions.dir) : path6.resolve(outputOptions.file, "..");
|
|
1448
1503
|
for (const fileName in bundle) {
|
|
1449
1504
|
const chunk = bundle[fileName];
|