vike 0.4.160 → 0.4.161-commit-0e9c635
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/cjs/node/cli/bin.js +5 -0
- package/dist/cjs/node/client/router.js +4 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +148 -0
- package/dist/cjs/node/plugin/plugins/buildConfig.js +61 -35
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -13
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +16 -4
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +5 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +11 -91
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +157 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -5
- package/dist/cjs/node/runtime/globalContext.js +15 -23
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +23 -28
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assertNodeVersion.js +2 -2
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/isVersionOrAbove.js +29 -0
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/index.js +1 -1
- package/dist/esm/node/cli/bin.js +3 -1
- package/dist/esm/node/client/router.d.ts +2 -0
- package/dist/esm/node/client/router.js +3 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +13 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +142 -0
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/buildConfig.js +60 -34
- package/dist/esm/node/plugin/plugins/commonConfig.js +6 -14
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +17 -5
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +5 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +13 -93
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +155 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/plugin/utils.d.ts +3 -2
- package/dist/esm/node/plugin/utils.js +3 -2
- package/dist/esm/node/prerender/runPrerender.js +15 -7
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +15 -23
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +6 -5
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +24 -29
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +3 -3
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/assertNodeVersion.js +2 -2
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/getOutDirs.d.ts +1 -0
- package/dist/esm/utils/isVersionOrAbove.d.ts +2 -0
- package/dist/esm/utils/isVersionOrAbove.js +26 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +2 -2
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
package/dist/cjs/node/cli/bin.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const cac_1 = require("cac");
|
|
4
7
|
const path_1 = require("path");
|
|
5
8
|
const runPrerender_js_1 = require("../prerender/runPrerender.js");
|
|
6
9
|
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
7
11
|
const cli = (0, cac_1.cac)(utils_js_1.projectInfo.projectName);
|
|
8
12
|
cli
|
|
9
13
|
.command('prerender', 'Pre-render the HTML of your pages', { allowUnknownOptions: true })
|
|
@@ -30,6 +34,7 @@ function assertOptions() {
|
|
|
30
34
|
'--outDir',
|
|
31
35
|
'--configFile'
|
|
32
36
|
].includes(option), 'Unknown option: ' + option);
|
|
37
|
+
(0, utils_js_1.assertWarning)(false, `You set ${picocolors_1.default.cyan(option)}, but passing options to ${picocolors_1.default.cyan('$ vike prerender')} is deprecated: use the config file instead. See https://vike.dev/command-prerender.`, { onlyOnce: true });
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
// Listen to unknown commands
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reload = exports.navigate = void 0;
|
|
3
|
+
exports.prefetch = exports.reload = exports.navigate = void 0;
|
|
4
4
|
const assert_js_1 = require("../../utils/assert.js");
|
|
5
5
|
// `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
|
|
6
6
|
const navigate = (() => warnNoEffect('navigate'));
|
|
7
7
|
exports.navigate = navigate;
|
|
8
8
|
const reload = (() => warnNoEffect('reload'));
|
|
9
9
|
exports.reload = reload;
|
|
10
|
+
const prefetch = (() => warnNoEffect('prefetch'));
|
|
11
|
+
exports.prefetch = prefetch;
|
|
10
12
|
function warnNoEffect(caller) {
|
|
11
|
-
(0, assert_js_1.assertWarning)(false, `Calling ${caller} on the server-side has no effect`, {
|
|
13
|
+
(0, assert_js_1.assertWarning)(false, `Calling ${caller}() on the server-side has no effect`, {
|
|
12
14
|
showStackTrace: true,
|
|
13
15
|
onlyOnce: false
|
|
14
16
|
});
|
|
@@ -10,7 +10,7 @@ const runPrerender_js_1 = require("../../prerender/runPrerender.js");
|
|
|
10
10
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
11
11
|
const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
const
|
|
13
|
+
const logErrorHint_js_1 = require("../../runtime/renderPage/logErrorHint.js");
|
|
14
14
|
let forceExit = false;
|
|
15
15
|
function autoFullBuild() {
|
|
16
16
|
let config;
|
|
@@ -88,7 +88,7 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
90
|
console.error(err);
|
|
91
|
-
(0,
|
|
91
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
92
92
|
process.exit(1);
|
|
93
93
|
}
|
|
94
94
|
if (configVike.prerender && !configVike.prerender.disableAutoRun) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fixServerAssets_isEnabled = exports.fixServerAssets = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const utils_js_1 = require("../../utils.js");
|
|
11
|
+
const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
12
|
+
const buildConfig_js_1 = require("../buildConfig.js");
|
|
13
|
+
/**
|
|
14
|
+
* true => use workaround config.build.ssrEmitAssets
|
|
15
|
+
* false => use workaround extractAssets plugin
|
|
16
|
+
*
|
|
17
|
+
* Only used by V1 design.
|
|
18
|
+
*/
|
|
19
|
+
function fixServerAssets_isEnabled() {
|
|
20
|
+
// We currently apply the workaround iff V1 design.
|
|
21
|
+
// Shall we allow the user to toggle between the two workarounds? E.g. based on https://vike.dev/includeAssetsImportedByServer.
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
exports.fixServerAssets_isEnabled = fixServerAssets_isEnabled;
|
|
25
|
+
/** https://github.com/vikejs/vike/issues/1339 */
|
|
26
|
+
async function fixServerAssets(outDirs) {
|
|
27
|
+
const clientManifest = await loadManifest(outDirs.outDirClient);
|
|
28
|
+
const serverManifest = await loadManifest(outDirs.outDirServer);
|
|
29
|
+
const { clientManifestMod, filesToCopy } = addServerAssets(clientManifest, serverManifest);
|
|
30
|
+
await copyAssets(filesToCopy, outDirs);
|
|
31
|
+
return clientManifestMod;
|
|
32
|
+
}
|
|
33
|
+
exports.fixServerAssets = fixServerAssets;
|
|
34
|
+
async function loadManifest(outDir) {
|
|
35
|
+
const manifestFilePath = path_1.default.posix.join(outDir, buildConfig_js_1.manifestTempFile);
|
|
36
|
+
const manifestFileContent = await promises_1.default.readFile(manifestFilePath, 'utf-8');
|
|
37
|
+
(0, utils_js_1.assert)(manifestFileContent);
|
|
38
|
+
const manifest = JSON.parse(manifestFileContent);
|
|
39
|
+
(0, utils_js_1.assert)(manifest);
|
|
40
|
+
return manifest;
|
|
41
|
+
}
|
|
42
|
+
async function copyAssets(filesToCopy, { outDirClient, outDirServer }) {
|
|
43
|
+
const assetsDirServer = path_1.default.posix.join(outDirServer, 'assets');
|
|
44
|
+
if (!filesToCopy.length)
|
|
45
|
+
return;
|
|
46
|
+
(0, utils_js_1.assert)((0, fs_1.existsSync)(assetsDirServer));
|
|
47
|
+
const concurrencyLimit = (0, utils_js_1.pLimit)(10);
|
|
48
|
+
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() => promises_1.default.cp(path_1.default.posix.join(outDirServer, file), path_1.default.posix.join(outDirClient, file), {
|
|
49
|
+
recursive: true
|
|
50
|
+
}))));
|
|
51
|
+
await promises_1.default.rm(assetsDirServer, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
// Add serverManifest resources to clientManifest
|
|
54
|
+
function addServerAssets(clientManifest, serverManifest) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const entriesClient = new Map();
|
|
57
|
+
const entriesServer = new Map();
|
|
58
|
+
for (const [key, entry] of Object.entries(clientManifest)) {
|
|
59
|
+
const pageId = getPageId(key);
|
|
60
|
+
if (!pageId)
|
|
61
|
+
continue;
|
|
62
|
+
const resources = collectResources(entry, clientManifest);
|
|
63
|
+
(0, utils_js_1.assert)(!entriesClient.has(pageId));
|
|
64
|
+
entriesClient.set(pageId, { key, ...resources });
|
|
65
|
+
}
|
|
66
|
+
for (const [key, entry] of Object.entries(serverManifest)) {
|
|
67
|
+
const pageId = getPageId(key);
|
|
68
|
+
if (!pageId)
|
|
69
|
+
continue;
|
|
70
|
+
const resources = collectResources(entry, serverManifest);
|
|
71
|
+
(0, utils_js_1.assert)(!entriesServer.has(pageId));
|
|
72
|
+
entriesServer.set(pageId, resources);
|
|
73
|
+
}
|
|
74
|
+
let filesToCopy = [];
|
|
75
|
+
for (const [pageId, entryClient] of entriesClient.entries()) {
|
|
76
|
+
const cssToAdd = [];
|
|
77
|
+
const assetsToAdd = [];
|
|
78
|
+
const entryServer = entriesServer.get(pageId);
|
|
79
|
+
if (entryServer) {
|
|
80
|
+
cssToAdd.push(...entryServer.css
|
|
81
|
+
.filter((cssServer) => !entryClient.css.some((cssClient) => cssServer.hash === cssClient.hash))
|
|
82
|
+
.map((css) => css.src));
|
|
83
|
+
assetsToAdd.push(...entryServer.assets
|
|
84
|
+
.filter((assertServer) => !entryClient.assets.some((assetClient) => assertServer.hash === assetClient.hash))
|
|
85
|
+
.map((asset) => asset.src));
|
|
86
|
+
}
|
|
87
|
+
const { key } = entryClient;
|
|
88
|
+
if (cssToAdd.length) {
|
|
89
|
+
filesToCopy.push(...cssToAdd);
|
|
90
|
+
(_a = clientManifest[key]).css ?? (_a.css = []);
|
|
91
|
+
clientManifest[key].css?.push(...cssToAdd);
|
|
92
|
+
}
|
|
93
|
+
if (assetsToAdd.length) {
|
|
94
|
+
filesToCopy.push(...assetsToAdd);
|
|
95
|
+
(_b = clientManifest[key]).assets ?? (_b.assets = []);
|
|
96
|
+
clientManifest[key].assets?.push(...assetsToAdd);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const clientManifestMod = clientManifest;
|
|
100
|
+
filesToCopy = (0, utils_js_1.unique)(filesToCopy);
|
|
101
|
+
return { clientManifestMod, filesToCopy };
|
|
102
|
+
}
|
|
103
|
+
function getPageId(key) {
|
|
104
|
+
// Normalize from:
|
|
105
|
+
// ../../virtual:vike:pageConfigValuesAll:client:/pages/index
|
|
106
|
+
// to:
|
|
107
|
+
// virtual:vike:pageConfigValuesAll:client:/pages/index
|
|
108
|
+
// (This seems to be needed only for vitest tests that use Vite's build() API with an inline config.)
|
|
109
|
+
key = key.substring(key.indexOf('virtual:vike'));
|
|
110
|
+
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(key);
|
|
111
|
+
return result && result.pageId;
|
|
112
|
+
}
|
|
113
|
+
function collectResources(entryRoot, manifest) {
|
|
114
|
+
const css = [];
|
|
115
|
+
const assets = [];
|
|
116
|
+
const entries = new Set([entryRoot]);
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
for (const entryImport of entry.imports ?? []) {
|
|
119
|
+
entries.add(manifest[entryImport]);
|
|
120
|
+
}
|
|
121
|
+
const entryCss = entry.css ?? [];
|
|
122
|
+
if (entry.file.endsWith('.css'))
|
|
123
|
+
entryCss.push(entry.file);
|
|
124
|
+
for (const src of entryCss) {
|
|
125
|
+
const hash = getHash(src);
|
|
126
|
+
css.push({ src, hash });
|
|
127
|
+
}
|
|
128
|
+
const entryAssets = entry.assets ?? [];
|
|
129
|
+
for (const src of entryAssets) {
|
|
130
|
+
const hash = getHash(src);
|
|
131
|
+
assets.push({ src, hash });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { css, assets };
|
|
135
|
+
}
|
|
136
|
+
// Use the hash of resources to determine whether they are equal. We need this, otherwise we get:
|
|
137
|
+
// ```html
|
|
138
|
+
// <head>
|
|
139
|
+
// <link rel="stylesheet" type="text/css" href="/assets/static/onRenderClient.2j6TxKIB.css">
|
|
140
|
+
// <link rel="stylesheet" type="text/css" href="/assets/static/onRenderHtml.2j6TxKIB.css">
|
|
141
|
+
// </head>
|
|
142
|
+
// ```
|
|
143
|
+
function getHash(src) {
|
|
144
|
+
// src is guarenteed to end with `.[hash][extname]`, see distFileNames.ts
|
|
145
|
+
const hash = src.split('.').at(-2);
|
|
146
|
+
(0, utils_js_1.assert)(hash);
|
|
147
|
+
return hash;
|
|
148
|
+
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
6
|
+
exports.manifestTempFile = exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
9
9
|
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
@@ -12,15 +12,21 @@ const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
|
12
12
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
13
13
|
const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
14
14
|
const module_1 = require("module");
|
|
15
|
-
const
|
|
15
|
+
const getClientEntry_js_1 = require("../../shared/getClientEntry.js");
|
|
16
16
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const fixServerAssets_js_1 = require("./buildConfig/fixServerAssets.js");
|
|
19
|
+
const index_js_1 = require("./importBuild/index.js");
|
|
20
|
+
const prependEntriesDir_js_1 = require("../../shared/prependEntriesDir.js");
|
|
18
21
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
19
22
|
const importMetaUrl = `file://${__filename}`;
|
|
20
23
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
21
24
|
const manifestTempFile = '_temp_manifest.json';
|
|
25
|
+
exports.manifestTempFile = manifestTempFile;
|
|
22
26
|
function buildConfig() {
|
|
23
|
-
let
|
|
27
|
+
let isServerAssetsFixEnabled;
|
|
28
|
+
let isSsrBuild;
|
|
29
|
+
let outDirs;
|
|
24
30
|
return {
|
|
25
31
|
name: 'vike:buildConfig',
|
|
26
32
|
apply: 'build',
|
|
@@ -28,37 +34,56 @@ function buildConfig() {
|
|
|
28
34
|
configResolved: {
|
|
29
35
|
order: 'post',
|
|
30
36
|
async handler(config) {
|
|
37
|
+
assertNodeEnv();
|
|
31
38
|
assertRollupInput(config);
|
|
32
39
|
const entries = await getEntries(config);
|
|
33
40
|
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
34
41
|
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)(entries, config);
|
|
35
42
|
addLogHook();
|
|
43
|
+
outDirs = (0, utils_js_1.getOutDirs)(config);
|
|
44
|
+
{
|
|
45
|
+
isServerAssetsFixEnabled = (0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && (await (0, getVikeConfig_js_1.isV1Design)(config, false));
|
|
46
|
+
if (isServerAssetsFixEnabled) {
|
|
47
|
+
// https://github.com/vikejs/vike/issues/1339
|
|
48
|
+
config.build.ssrEmitAssets = true;
|
|
49
|
+
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
50
|
+
config.build.cssMinify = 'esbuild';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
36
53
|
}
|
|
37
54
|
},
|
|
38
55
|
config(config) {
|
|
39
|
-
|
|
56
|
+
assertNodeEnv();
|
|
57
|
+
isSsrBuild = (0, utils_js_1.viteIsSSR)(config);
|
|
40
58
|
return {
|
|
41
59
|
build: {
|
|
42
60
|
outDir: (0, utils_js_1.resolveOutDir)(config),
|
|
43
|
-
manifest:
|
|
44
|
-
copyPublicDir: !
|
|
61
|
+
manifest: manifestTempFile,
|
|
62
|
+
copyPublicDir: !isSsrBuild
|
|
45
63
|
}
|
|
46
64
|
};
|
|
47
65
|
},
|
|
66
|
+
buildStart() {
|
|
67
|
+
assertNodeEnv();
|
|
68
|
+
},
|
|
48
69
|
async writeBundle(options, bundle) {
|
|
49
|
-
|
|
50
|
-
/* Fails with @vitejs/plugin-legacy because writeBundle() is called twice during the client build (once for normal client assets and a second time for legacy assets), see reproduction at https://github.com/vikejs/vike/issues/1154
|
|
51
|
-
assert(generateManifest === !!manifestEntry)
|
|
52
|
-
*/
|
|
53
|
-
if (manifestEntry) {
|
|
54
|
-
const { dir } = options;
|
|
55
|
-
(0, utils_js_1.assert)(dir);
|
|
56
|
-
const manifestFilePathOld = path_1.default.join(dir, manifestEntry.fileName);
|
|
70
|
+
if (isSsrBuild) {
|
|
57
71
|
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
58
72
|
// - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
|
|
59
73
|
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
60
|
-
const
|
|
61
|
-
|
|
74
|
+
const assetsJsonFilePath = path_1.default.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
75
|
+
const clientManifestFilePath = path_1.default.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
76
|
+
const serverManifestFilePath = path_1.default.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
77
|
+
if (!isServerAssetsFixEnabled) {
|
|
78
|
+
await promises_1.default.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const clientManifestMod = await (0, fixServerAssets_js_1.fixServerAssets)(outDirs);
|
|
82
|
+
await promises_1.default.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
83
|
+
}
|
|
84
|
+
await promises_1.default.rm(clientManifestFilePath);
|
|
85
|
+
await promises_1.default.rm(serverManifestFilePath);
|
|
86
|
+
await (0, index_js_1.set_constant_ASSETS_MAP)(options, bundle);
|
|
62
87
|
}
|
|
63
88
|
}
|
|
64
89
|
};
|
|
@@ -112,7 +137,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
112
137
|
let hasClientRouting = false;
|
|
113
138
|
let hasServerRouting = false;
|
|
114
139
|
let clientEntries = {};
|
|
115
|
-
let
|
|
140
|
+
let clientEntryList = [];
|
|
116
141
|
pageConfigs.forEach((pageConfig) => {
|
|
117
142
|
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
118
143
|
if (configValue?.value) {
|
|
@@ -127,15 +152,15 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
127
152
|
clientEntries[entryName] = entryTarget;
|
|
128
153
|
}
|
|
129
154
|
{
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
155
|
+
const clientEntry = (0, getClientEntry_js_1.getClientEntry)(pageConfig);
|
|
156
|
+
if (clientEntry) {
|
|
157
|
+
clientEntryList.push(clientEntry);
|
|
133
158
|
}
|
|
134
159
|
}
|
|
135
160
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const { entryName, entryTarget } =
|
|
161
|
+
clientEntryList = (0, utils_js_1.unique)(clientEntryList);
|
|
162
|
+
clientEntryList.forEach((clientEntry) => {
|
|
163
|
+
const { entryName, entryTarget } = getEntryFromClientEntry(clientEntry, config);
|
|
139
164
|
clientEntries[entryName] = entryTarget;
|
|
140
165
|
});
|
|
141
166
|
return { hasClientRouting, hasServerRouting, clientEntries };
|
|
@@ -158,12 +183,18 @@ async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
|
158
183
|
(0, utils_js_1.assert)(includeAssetsImportedByServer);
|
|
159
184
|
addExtractAssetsQuery = true;
|
|
160
185
|
}
|
|
161
|
-
const { entryName, entryTarget } =
|
|
186
|
+
const { entryName, entryTarget } = getEntryFromClientEntry(pageFile, config, addExtractAssetsQuery);
|
|
162
187
|
pageFileEntries[entryName] = entryTarget;
|
|
163
188
|
});
|
|
164
189
|
return pageFileEntries;
|
|
165
190
|
}
|
|
166
|
-
function
|
|
191
|
+
function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
192
|
+
if ((0, utils_js_1.isNpmPackageImport)(clientEntry)) {
|
|
193
|
+
const entryTarget = clientEntry;
|
|
194
|
+
const entryName = (0, prependEntriesDir_js_1.prependEntriesDir)(clientEntry);
|
|
195
|
+
return { entryName, entryTarget };
|
|
196
|
+
}
|
|
197
|
+
const filePath = clientEntry;
|
|
167
198
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
168
199
|
(0, utils_js_1.assert)(filePath.startsWith('/'));
|
|
169
200
|
let entryTarget = (0, utils_js_1.getFilePathAbsolute)(filePath, config);
|
|
@@ -173,24 +204,16 @@ function getEntryFromFilePath(filePath, config, addExtractAssetsQuery) {
|
|
|
173
204
|
if (addExtractAssetsQuery)
|
|
174
205
|
entryName = (0, extractAssetsQuery_js_1.extractAssetsAddQuery)(entryName);
|
|
175
206
|
entryName = (0, utils_js_1.removeFileExtention)(entryName);
|
|
176
|
-
entryName = prependEntriesDir(entryName);
|
|
207
|
+
entryName = (0, prependEntriesDir_js_1.prependEntriesDir)(entryName);
|
|
177
208
|
return { entryName, entryTarget };
|
|
178
209
|
}
|
|
179
210
|
function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
180
211
|
let { pageId } = pageConfig;
|
|
181
212
|
const entryTarget = (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, isForClientSide);
|
|
182
213
|
let entryName = pageId;
|
|
183
|
-
entryName = prependEntriesDir(entryName);
|
|
214
|
+
entryName = (0, prependEntriesDir_js_1.prependEntriesDir)(entryName);
|
|
184
215
|
return { entryName, entryTarget };
|
|
185
216
|
}
|
|
186
|
-
function prependEntriesDir(entryName) {
|
|
187
|
-
if (entryName.startsWith('/')) {
|
|
188
|
-
entryName = entryName.slice(1);
|
|
189
|
-
}
|
|
190
|
-
(0, utils_js_1.assert)(!entryName.startsWith('/'));
|
|
191
|
-
entryName = `entries/${entryName}`;
|
|
192
|
-
return entryName;
|
|
193
|
-
}
|
|
194
217
|
function resolve(filePath) {
|
|
195
218
|
(0, utils_js_1.assert)(filePath.startsWith('dist/'));
|
|
196
219
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/
|
|
@@ -230,3 +253,6 @@ function assertRollupInput(config) {
|
|
|
230
253
|
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
231
254
|
}
|
|
232
255
|
exports.assertRollupInput = assertRollupInput;
|
|
256
|
+
function assertNodeEnv() {
|
|
257
|
+
(0, utils_js_1.assertNodeEnvIsNotDev)('building');
|
|
258
|
+
}
|
|
@@ -31,7 +31,7 @@ function commonConfig() {
|
|
|
31
31
|
overrideViteDefaultPort(config);
|
|
32
32
|
/* TODO: do this after implementing vike.config.js and new setting transformLinkedDependencies (or probably a better name like transpileLinkedDependencies/bundleLinkedDependencies or something else)
|
|
33
33
|
overrideViteDefaultSsrExternal(config)
|
|
34
|
-
|
|
34
|
+
//*/
|
|
35
35
|
workaroundCI(config);
|
|
36
36
|
(0, buildConfig_js_1.assertRollupInput)(config);
|
|
37
37
|
(0, assertResolveAlias_js_1.assertResolveAlias)(config);
|
|
@@ -52,21 +52,13 @@ function overrideViteDefaultPort(config) {
|
|
|
52
52
|
(_b = config.preview).port ?? (_b.port = 3000);
|
|
53
53
|
}
|
|
54
54
|
/*
|
|
55
|
+
import { version } from 'vite'
|
|
55
56
|
function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
|
|
56
|
-
if (!
|
|
57
|
+
if (!isVersionOrAbove(version, '5.0.12')) return
|
|
57
58
|
// @ts-ignore Not released yet: https://github.com/vitejs/vite/pull/10939/files#diff-5a3d42620df2c6b17e25f440ffdb67683dee7ef57317674d19f41d5f30502310L5
|
|
58
59
|
config.ssr.external ??= true
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
function isViteVersionWithSsrExternalTrue(): boolean {
|
|
62
|
-
const versionParts = version.split('.').map((s) => parseInt(s, 10)) as [number, number, number]
|
|
63
|
-
assert(versionParts.length === 3)
|
|
64
|
-
if (versionParts[0] > 5) return true
|
|
65
|
-
if (versionParts[1] > 0) return true
|
|
66
|
-
if (versionParts[2] >= 12) return true
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
*/
|
|
61
|
+
//*/
|
|
70
62
|
// Workaround GitHub Action failing to access the server
|
|
71
63
|
function workaroundCI(config) {
|
|
72
64
|
var _a, _b;
|
|
@@ -76,7 +68,7 @@ function workaroundCI(config) {
|
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
function assertEsm(userViteRoot) {
|
|
79
|
-
const packageJsonPath = (0, utils_js_1.
|
|
71
|
+
const packageJsonPath = (0, utils_js_1.findFile)('package.json', userViteRoot);
|
|
80
72
|
if (!packageJsonPath)
|
|
81
73
|
return;
|
|
82
74
|
const packageJson = require_(packageJsonPath);
|
|
@@ -54,7 +54,7 @@ async function getStemPackages(userAppRootDir) {
|
|
|
54
54
|
}
|
|
55
55
|
exports.getStemPackages = getStemPackages;
|
|
56
56
|
function findUserRootDir(userAppRootDir) {
|
|
57
|
-
const userPkgJsonPath = (0, utils_js_1.
|
|
57
|
+
const userPkgJsonPath = (0, utils_js_1.findFile)('package.json', userAppRootDir);
|
|
58
58
|
(0, utils_js_1.assertUsage)(userPkgJsonPath, `Couldn't find package.json in any parent directory starting from ${userAppRootDir}`);
|
|
59
59
|
return (0, utils_js_1.toPosixPath)(path_1.default.dirname(userPkgJsonPath));
|
|
60
60
|
}
|
|
@@ -24,9 +24,17 @@ function distFileNames() {
|
|
|
24
24
|
if (!('chunkFileNames' in rollupOutput)) {
|
|
25
25
|
rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
|
|
26
26
|
}
|
|
27
|
-
if (!('
|
|
27
|
+
if (!('assetFileNames' in rollupOutput)) {
|
|
28
28
|
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
|
|
29
29
|
}
|
|
30
|
+
else {
|
|
31
|
+
// If a user needs this:
|
|
32
|
+
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
33
|
+
// - It's needed for getHash() of fixServerAssets()
|
|
34
|
+
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
35
|
+
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
36
|
+
(0, utils_js_1.assertUsage)(false, "Setting config.build.rollupOptions.output.assetFileNames is currently forbidden. (It's possible to support, thus contact a maintainer if you need this.)");
|
|
37
|
+
}
|
|
30
38
|
});
|
|
31
39
|
}
|
|
32
40
|
};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.applyEnvVar = exports.envVarsPlugin = void 0;
|
|
4
4
|
const vite_1 = require("vite");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
|
+
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
6
7
|
function envVarsPlugin() {
|
|
7
8
|
let envsAll;
|
|
8
9
|
let config;
|
|
@@ -62,8 +63,11 @@ function envVarsPlugin() {
|
|
|
62
63
|
// Apply
|
|
63
64
|
code = applyEnvVar(envName, envVal, code);
|
|
64
65
|
});
|
|
65
|
-
//
|
|
66
|
-
|
|
66
|
+
// Line numbers didn't change.
|
|
67
|
+
// - We only break the column number of a couple of lines, wich is acceptable.
|
|
68
|
+
// - Anyways, I'm not even sure Vite supports high-resolution column number source mapping.
|
|
69
|
+
const ret = (0, rollupSourceMap_js_1.sourceMapPassthrough)(code);
|
|
70
|
+
return ret;
|
|
67
71
|
}
|
|
68
72
|
};
|
|
69
73
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// -
|
|
2
|
+
// Remove this workaround if the other workaround config.build.ssrEmitAssets turns out to be reliable.
|
|
3
|
+
// - Remove this file then revert this commit: https://github.com/vikejs/vike/commit/805a18974f13420a78fcc30fdd676696e405c3ca
|
|
4
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
6
|
};
|
|
@@ -11,8 +11,11 @@ const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
|
11
11
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
12
12
|
const isAsset_js_1 = require("../shared/isAsset.js");
|
|
13
13
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
14
|
-
const
|
|
14
|
+
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
15
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
|
+
const fixServerAssets_js_1 = require("./buildConfig/fixServerAssets.js");
|
|
17
|
+
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
18
|
+
const assertV1Design_js_1 = require("../../shared/assertV1Design.js");
|
|
16
19
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
17
20
|
exports.extractAssetsRE = extractAssetsRE;
|
|
18
21
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
@@ -24,6 +27,8 @@ const debugEnabled = (0, utils_js_1.isDebugEnabled)(debugNamespace);
|
|
|
24
27
|
function extractAssetsPlugin() {
|
|
25
28
|
let config;
|
|
26
29
|
let configVike;
|
|
30
|
+
let vikeConfig;
|
|
31
|
+
let isServerAssetsFixEnabled;
|
|
27
32
|
return [
|
|
28
33
|
// This plugin removes all JavaScript from server-side only code, so that only CSS imports remains. (And also satic files imports e.g. `import logoURL from './logo.svg.js'`).
|
|
29
34
|
{
|
|
@@ -35,13 +40,18 @@ function extractAssetsPlugin() {
|
|
|
35
40
|
if (!extractAssetsRE.test(id)) {
|
|
36
41
|
return;
|
|
37
42
|
}
|
|
43
|
+
if (isServerAssetsFixEnabled) {
|
|
44
|
+
// I'm guessing isServerAssetsFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
45
|
+
(0, assertV1Design_js_1.assertV1Design)(true, vikeConfig.pageConfigs);
|
|
46
|
+
(0, utils_js_1.assert)(false);
|
|
47
|
+
}
|
|
38
48
|
(0, utils_js_1.assert)(configVike.includeAssetsImportedByServer);
|
|
39
49
|
(0, utils_js_1.assert)(!(0, utils_js_1.viteIsSSR_options)(options));
|
|
40
50
|
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
41
51
|
const moduleNames = getImportedModules(importStatements);
|
|
42
52
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
43
53
|
debugTransformResult(id, code, importStatements);
|
|
44
|
-
return (0,
|
|
54
|
+
return (0, rollupSourceMap_js_1.sourceMapRemove)(code);
|
|
45
55
|
}
|
|
46
56
|
},
|
|
47
57
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -132,6 +142,8 @@ function extractAssetsPlugin() {
|
|
|
132
142
|
async configResolved(config_) {
|
|
133
143
|
configVike = await (0, getConfigVike_js_1.getConfigVike)(config_);
|
|
134
144
|
config = config_;
|
|
145
|
+
vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config, false);
|
|
146
|
+
isServerAssetsFixEnabled = (0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && (await (0, getVikeConfig_js_1.isV1Design)(config, false));
|
|
135
147
|
},
|
|
136
148
|
load(id) {
|
|
137
149
|
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.extractExportNamesRE = exports.isUsingClientRouter = exports.extractExportNamesPlugin = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
6
|
-
const
|
|
6
|
+
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
7
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
8
8
|
exports.extractExportNamesRE = extractExportNamesRE;
|
|
9
9
|
const debugNamespace = 'vike:extractExportNames';
|
|
@@ -40,7 +40,7 @@ async function getExtractExportNamesCode(src, isClientSide, isProduction, id) {
|
|
|
40
40
|
globalObject.usesClientRouter = true;
|
|
41
41
|
}
|
|
42
42
|
const code = getCode(exportNames, wildcardReExports, isClientSide, isProduction, id);
|
|
43
|
-
return (0,
|
|
43
|
+
return (0, rollupSourceMap_js_1.sourceMapRemove)(code);
|
|
44
44
|
}
|
|
45
45
|
function getCode(exportNames, wildcardReExports, isClientSide, isProduction, id) {
|
|
46
46
|
let code = '';
|
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getVikeManifest = void 0;
|
|
7
4
|
const utils_js_1 = require("../../utils.js");
|
|
8
5
|
const assertPluginManifest_js_1 = require("../../../shared/assertPluginManifest.js");
|
|
9
6
|
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
7
|
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
12
|
-
function getVikeManifest(
|
|
8
|
+
function getVikeManifest(configVike) {
|
|
13
9
|
const runtimeManifest = (0, globalContext_js_1.getRuntimeManifest)(configVike);
|
|
14
10
|
const manifest = {
|
|
15
11
|
version: utils_js_1.projectInfo.projectVersion,
|
|
16
12
|
usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(), // TODO/v1-release: remove
|
|
17
|
-
manifestKeyMap: getManifestKeyMap(configVike, config),
|
|
18
13
|
...runtimeManifest
|
|
19
14
|
};
|
|
20
15
|
(0, assertPluginManifest_js_1.assertPluginManifest)(manifest);
|
|
21
16
|
return manifest;
|
|
22
17
|
}
|
|
23
18
|
exports.getVikeManifest = getVikeManifest;
|
|
24
|
-
function getManifestKeyMap(configVike, config) {
|
|
25
|
-
const manifestKeyMap = {};
|
|
26
|
-
configVike.extensions
|
|
27
|
-
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
28
|
-
.flat()
|
|
29
|
-
.filter(utils_js_1.isNotNullish)
|
|
30
|
-
.forEach(({ importPath, filePath }) => {
|
|
31
|
-
// Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
|
|
32
|
-
const filePathRelative = path_1.default.posix.relative(config.root, (0, utils_js_1.toPosixPath)(filePath));
|
|
33
|
-
(0, utils_js_1.assertPosixPath)(filePathRelative);
|
|
34
|
-
(0, utils_js_1.assertPosixPath)(importPath);
|
|
35
|
-
manifestKeyMap[importPath] = filePathRelative;
|
|
36
|
-
});
|
|
37
|
-
return manifestKeyMap;
|
|
38
|
-
}
|