vike 0.4.236 → 0.4.237
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/client/shared/createGetGlobalContextClient.js +20 -12
- package/dist/cjs/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +118 -31
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
- package/dist/cjs/node/runtime/html/serializeContext.js +25 -64
- package/dist/cjs/node/runtime/html/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -12
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
- package/dist/cjs/node/runtime/renderPage.js +9 -8
- package/dist/cjs/node/runtime/utils.js +4 -0
- package/dist/cjs/node/shared/utils.js +1 -0
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +10 -4
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +22 -14
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +118 -72
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +51 -0
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +6 -3
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +4 -5
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/node/vite/shared/getMagicString.js +18 -0
- package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +10 -0
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +7 -18
- package/dist/cjs/node/vite/utils.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +27 -6
- package/dist/cjs/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +13 -13
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +7 -5
- package/dist/cjs/utils/cast.js +1 -1
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/cjs/utils/isRunnableDevEnvironment.js +9 -0
- package/dist/cjs/utils/virtualFileId.js +39 -0
- package/dist/esm/client/node.js +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +39 -22
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +43 -30
- package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/utils.js +2 -0
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.js +20 -12
- package/dist/esm/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
- package/dist/esm/node/runtime/globalContext.d.ts +35 -55
- package/dist/esm/node/runtime/globalContext.js +119 -32
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +4 -2
- package/dist/esm/node/runtime/html/serializeContext.d.ts +11 -6
- package/dist/esm/node/runtime/html/serializeContext.js +25 -64
- package/dist/esm/node/runtime/html/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +11 -34
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -13
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +0 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +24 -71
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
- package/dist/esm/node/runtime/renderPage.d.ts +11 -33
- package/dist/esm/node/runtime/renderPage.js +9 -8
- package/dist/esm/node/runtime/utils.d.ts +4 -0
- package/dist/esm/node/runtime/utils.js +4 -0
- package/dist/esm/node/shared/utils.d.ts +1 -0
- package/dist/esm/node/shared/utils.js +1 -0
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +11 -5
- package/dist/esm/node/vite/index.js +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +22 -14
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +120 -74
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +49 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +2 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +6 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +3 -4
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/node/vite/shared/getMagicString.d.ts +9 -0
- package/dist/esm/node/vite/shared/getMagicString.js +13 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.d.ts +2 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.js +8 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +8 -19
- package/dist/esm/node/vite/utils.d.ts +1 -0
- package/dist/esm/node/vite/utils.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +28 -7
- package/dist/esm/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +14 -14
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/Config.d.ts +33 -98
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +7 -5
- package/dist/esm/utils/cast.d.ts +2 -2
- package/dist/esm/utils/cast.js +1 -1
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +7 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/esm/utils/isRunnableDevEnvironment.d.ts +3 -0
- package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
- package/dist/esm/utils/objectFilter.d.ts +1 -1
- package/dist/esm/utils/virtualFileId.d.ts +6 -0
- package/dist/esm/{node/shared/virtualFiles.js → utils/virtualFileId.js} +15 -17
- package/package.json +14 -5
- package/dist/cjs/node/shared/virtualFiles.js +0 -41
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.pluginModuleBanner = pluginModuleBanner;
|
|
7
7
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
|
-
const
|
|
8
|
+
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
10
10
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
11
11
|
// But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
|
|
@@ -28,7 +28,7 @@ function pluginModuleBanner() {
|
|
|
28
28
|
}
|
|
29
29
|
if (id.startsWith('\0'))
|
|
30
30
|
id = id;
|
|
31
|
-
id = (0,
|
|
31
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
32
32
|
if (id.startsWith(config.root))
|
|
33
33
|
id = id.slice(config.root.length + 1);
|
|
34
34
|
id = id.replaceAll('*/', '*\\/'); // https://github.com/vikejs/vike/issues/2377
|
|
@@ -16,6 +16,7 @@ const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInter
|
|
|
16
16
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
17
17
|
const context_js_2 = require("../../prerender/context.js");
|
|
18
18
|
const pluginName = 'vike:pluginCommon';
|
|
19
|
+
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
19
20
|
function pluginCommon(vikeVitePluginOptions) {
|
|
20
21
|
return [
|
|
21
22
|
{
|
|
@@ -7,70 +7,109 @@ const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigIn
|
|
|
7
7
|
const pluginBuildConfig_js_1 = require("../pluginBuild/pluginBuildConfig.js");
|
|
8
8
|
const virtualFileEntry_js_1 = require("../../../shared/virtualFiles/virtualFileEntry.js");
|
|
9
9
|
const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
10
|
+
const getConfigValueSourcesRelevant_js_1 = require("../pluginVirtualFiles/getConfigValueSourcesRelevant.js");
|
|
10
11
|
const debug = (0, utils_js_1.createDebugger)('vike:optimizeDeps');
|
|
11
12
|
async function determineOptimizeDeps(config) {
|
|
12
13
|
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
13
14
|
const { _pageConfigs: pageConfigs } = vikeConfig;
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
|
|
16
|
+
config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
|
|
17
|
+
config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
|
|
18
|
+
// Workaround until https://github.com/vitejs/vite-plugin-react/issues/650
|
|
19
|
+
// - TODO/soon: remove workaround once https://github.com/vitejs/vite/pull/20495 is released
|
|
20
|
+
includeServer.push('react/jsx-dev-runtime');
|
|
21
|
+
for (const envName in config.environments) {
|
|
22
|
+
const env = config.environments[envName];
|
|
23
|
+
if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
|
|
24
|
+
env.optimizeDeps.include = add(env.optimizeDeps.include, includeServer);
|
|
25
|
+
env.optimizeDeps.entries = add(env.optimizeDeps.entries, entriesServer);
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
|
-
/* Other Vite plugins may populate optimizeDeps, e.g. Cypress: https://github.com/vikejs/vike/issues/386
|
|
24
|
-
assert(config.optimizeDeps.entries === undefined)
|
|
25
|
-
*/
|
|
26
|
-
config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
|
|
27
|
-
config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
|
|
28
28
|
if (debug.isActivated)
|
|
29
|
-
debug('
|
|
29
|
+
debug('optimizeDeps', {
|
|
30
30
|
'config.optimizeDeps.entries': config.optimizeDeps.entries,
|
|
31
31
|
'config.optimizeDeps.include': config.optimizeDeps.include,
|
|
32
|
+
'config.optimizeDeps.exclude': config.optimizeDeps.exclude,
|
|
33
|
+
// @ts-ignore Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
34
|
+
'config.ssr.optimizeDeps.entries': config.ssr.optimizeDeps.entries,
|
|
35
|
+
'config.ssr.optimizeDeps.include': config.ssr.optimizeDeps.include,
|
|
36
|
+
'config.ssr.optimizeDeps.exclude': config.ssr.optimizeDeps.exclude,
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
async function getPageDeps(config, pageConfigs) {
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
|
|
40
|
+
let entriesClient = [];
|
|
41
|
+
let entriesServer = [];
|
|
42
|
+
let includeClient = [];
|
|
43
|
+
let includeServer = [];
|
|
44
|
+
const addEntry = (e, isForClientSide, definedAt) => {
|
|
38
45
|
(0, utils_js_1.assert)(e);
|
|
39
|
-
entries
|
|
46
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
47
|
+
(0, utils_js_1.assert)((0, utils_js_1.isVirtualFileId)(e) || (0, utils_js_1.isFilePathAbsoluteFilesystem)(e));
|
|
48
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
49
|
+
return;
|
|
50
|
+
if (isForClientSide) {
|
|
51
|
+
entriesClient.push(e);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
entriesServer.push(e);
|
|
55
|
+
}
|
|
40
56
|
};
|
|
41
|
-
const addInclude = (e) => {
|
|
57
|
+
const addInclude = (e, isForClientSide, definedAt) => {
|
|
42
58
|
(0, utils_js_1.assert)(e);
|
|
43
|
-
//
|
|
59
|
+
// optimizeDeps.include expects npm packages
|
|
60
|
+
(0, utils_js_1.assert)(!e.startsWith('/'));
|
|
61
|
+
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
44
62
|
(0, utils_js_1.assertIsImportPathNpmPackage)(e);
|
|
45
|
-
|
|
63
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
64
|
+
return;
|
|
65
|
+
if (isForClientSide) {
|
|
66
|
+
includeClient.push(e);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
includeServer.push(e);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const isExcluded = (e, isForClientSide, definedAt) => {
|
|
73
|
+
const exclude = isForClientSide ? config.optimizeDeps.exclude : config.ssr.optimizeDeps.exclude;
|
|
74
|
+
if (!exclude)
|
|
75
|
+
return false;
|
|
76
|
+
if (definedAt?.importPathAbsolute) {
|
|
77
|
+
const npmPackageName = (0, utils_js_1.getNpmPackageName)(definedAt.importPathAbsolute);
|
|
78
|
+
if (npmPackageName && exclude.includes(npmPackageName))
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return exclude.includes(e);
|
|
46
82
|
};
|
|
47
83
|
// V1 design
|
|
48
84
|
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const npmPackageName = (0, utils_js_1.getNpmPackageName)(definedAt.importPathAbsolute);
|
|
63
|
-
if (npmPackageName && config.optimizeDeps.exclude?.includes(npmPackageName))
|
|
85
|
+
;
|
|
86
|
+
[true, false].forEach((isForClientSide) => {
|
|
87
|
+
pageConfigs.forEach((pageConfig) => {
|
|
88
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
89
|
+
const runtimeEnv = {
|
|
90
|
+
isForClientSide,
|
|
91
|
+
isDev: true,
|
|
92
|
+
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
93
|
+
isClientRouting: true,
|
|
94
|
+
};
|
|
95
|
+
const sourcesRelevant = (0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(configName, runtimeEnv, pageConfig);
|
|
96
|
+
sourcesRelevant.forEach((configValueSource) => {
|
|
97
|
+
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
64
98
|
return;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
99
|
+
const { definedAt } = configValueSource;
|
|
100
|
+
if (definedAt.definedBy)
|
|
101
|
+
return;
|
|
102
|
+
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
103
|
+
addEntry(
|
|
104
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
105
|
+
definedAt.filePathAbsoluteFilesystem, isForClientSide, definedAt);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
addInclude(
|
|
109
|
+
// optimizeDeps.include expects npm packages
|
|
110
|
+
definedAt.importPathAbsolute, isForClientSide, definedAt);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
74
113
|
});
|
|
75
114
|
});
|
|
76
115
|
});
|
|
@@ -82,35 +121,42 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
82
121
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
83
122
|
const entry = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
84
123
|
const { filePathAbsoluteFilesystem } = entry;
|
|
85
|
-
addEntry(filePathAbsoluteFilesystem);
|
|
124
|
+
addEntry(filePathAbsoluteFilesystem, true);
|
|
86
125
|
});
|
|
87
126
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
127
|
+
// Add virtual files.
|
|
128
|
+
// - This doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
129
|
+
// - Should we make it work? E.g. by creating a temporary file at node_modules/.vike/virtualFiles.js
|
|
130
|
+
// - Or should we remove it? And make sure getPageDeps() also works for aliased import paths
|
|
131
|
+
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
132
|
+
{
|
|
133
|
+
const { hasClientRouting, hasServerRouting, clientEntries } = (0, pluginBuildConfig_js_1.analyzeClientEntries)(pageConfigs, config);
|
|
134
|
+
Object.values(clientEntries).forEach((e) => addEntry(e, true));
|
|
135
|
+
if (hasClientRouting)
|
|
136
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientCR, true);
|
|
137
|
+
if (hasServerRouting)
|
|
138
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientSR, true);
|
|
139
|
+
}
|
|
140
|
+
entriesClient = entriesClient;
|
|
141
|
+
entriesServer = entriesServer;
|
|
142
|
+
includeClient = includeClient;
|
|
143
|
+
includeServer = includeServer;
|
|
144
|
+
return {
|
|
145
|
+
entriesClient,
|
|
146
|
+
entriesServer,
|
|
147
|
+
includeClient,
|
|
148
|
+
includeServer,
|
|
149
|
+
};
|
|
100
150
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
(0, utils_js_1.assert)(false);
|
|
151
|
+
function add(input, listAddendum) {
|
|
152
|
+
const list = !input ? [] : (0, utils_js_1.isArray)(input) ? unique(input) : [input];
|
|
153
|
+
listAddendum.forEach((e) => {
|
|
154
|
+
if (!list.includes(e))
|
|
155
|
+
list.push(e);
|
|
156
|
+
});
|
|
157
|
+
return list;
|
|
109
158
|
}
|
|
110
|
-
function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (include === undefined)
|
|
114
|
-
return [];
|
|
115
|
-
(0, utils_js_1.assert)(false);
|
|
159
|
+
function unique(arr) {
|
|
160
|
+
const arrUnique = Array.from(new Set(arr));
|
|
161
|
+
return arr.length !== arrUnique.length ? arrUnique : arr;
|
|
116
162
|
}
|
|
@@ -12,7 +12,7 @@ const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
|
12
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
13
13
|
const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
|
|
14
14
|
// TO-DO/eventually:
|
|
15
|
-
// - Make
|
|
15
|
+
// - Make ({}) work inside +config.js
|
|
16
16
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
17
17
|
// - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
18
18
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
@@ -39,7 +39,7 @@ function pluginEnvVars() {
|
|
|
39
39
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
40
40
|
if (!id.startsWith(config.root))
|
|
41
41
|
return;
|
|
42
|
-
if (!code.includes('
|
|
42
|
+
if (!code.includes('({}).'))
|
|
43
43
|
return;
|
|
44
44
|
const isBuild = config.command === 'build';
|
|
45
45
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
@@ -52,7 +52,7 @@ function pluginEnvVars() {
|
|
|
52
52
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
53
53
|
})
|
|
54
54
|
.map(([envName, envVal]) => {
|
|
55
|
-
const envStatement = `
|
|
55
|
+
const envStatement = `({}).${envName}`;
|
|
56
56
|
const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
57
57
|
// Security check
|
|
58
58
|
{
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.extractAssetsRE = void 0;
|
|
9
9
|
exports.pluginExtractAssets = pluginExtractAssets;
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
|
-
const virtualFiles_js_1 = require("../../shared/virtualFiles.js");
|
|
12
11
|
const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
13
12
|
const isAsset_js_1 = require("../shared/isAsset.js");
|
|
14
13
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
@@ -124,9 +123,9 @@ function pluginExtractAssets() {
|
|
|
124
123
|
name: 'vike:pluginExtractAssets-3',
|
|
125
124
|
apply: 'build',
|
|
126
125
|
load(id) {
|
|
127
|
-
if (!(0,
|
|
126
|
+
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
128
127
|
return undefined;
|
|
129
|
-
id = (0,
|
|
128
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
130
129
|
if (id === EMPTY_MODULE_ID) {
|
|
131
130
|
return '// Erased by vike:pluginExtractAssets';
|
|
132
131
|
}
|
|
@@ -153,7 +152,7 @@ function pluginExtractAssets() {
|
|
|
153
152
|
}
|
|
154
153
|
function emptyModule(file, importer) {
|
|
155
154
|
debugOperation('NUKED', file, importer);
|
|
156
|
-
return (0,
|
|
155
|
+
return (0, utils_js_1.addVirtualFileIdPrefix)(EMPTY_MODULE_ID);
|
|
157
156
|
}
|
|
158
157
|
function appendExtractAssetsQuery(file, importer) {
|
|
159
158
|
debugOperation('TRANSFORMED', file, importer);
|
|
@@ -81,12 +81,12 @@ function injectHmr(code, isClientSide, isProduction) {
|
|
|
81
81
|
}
|
|
82
82
|
if (isClientSide) {
|
|
83
83
|
code += '\n';
|
|
84
|
-
code += `if (
|
|
84
|
+
code += `if ((undefined)) (undefined).accept((mod) => { exportNames.length=0; exportNames.push(...mod.exportNames); });`;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
// Ensure Vite considers the module as `isSelfAccepting`. (Needed because Vite's module graph erroneously conflates the Vite server-side modules with their client-side counterparts.)
|
|
88
88
|
code += '\n';
|
|
89
|
-
code += 'if(false){
|
|
89
|
+
code += 'if(false){(undefined).accept(()=>{})};';
|
|
90
90
|
}
|
|
91
91
|
return code;
|
|
92
92
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginNonRunnableDev = pluginNonRunnableDev;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const resolveClientEntriesDev_js_1 = require("../shared/resolveClientEntriesDev.js");
|
|
6
|
+
const retrieveAssetsDev_js_1 = require("../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js");
|
|
7
|
+
const getViteConfigRuntime_js_1 = require("../shared/getViteConfigRuntime.js");
|
|
8
|
+
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
9
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
10
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
11
|
+
return {
|
|
12
|
+
async transformIndexHtmlRPC(html) {
|
|
13
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
14
|
+
},
|
|
15
|
+
// TODO/now: dedupe retrievePageAssetsDevRPC and retrievePageAssetsDev()
|
|
16
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
17
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => (0, resolveClientEntriesDev_js_1.resolveClientEntriesDev)(clientEntry, viteDevServer));
|
|
18
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
19
|
+
return { clientEntriesSrc, assetUrls };
|
|
20
|
+
},
|
|
21
|
+
async getViteConfigRuntimeRPC() {
|
|
22
|
+
return (0, getViteConfigRuntime_js_1.getViteConfigRuntime)(viteDevServer.config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function pluginNonRunnableDev() {
|
|
27
|
+
const runtimeGlobalContextFilePath = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/node/runtime/globalContext.js');
|
|
28
|
+
let config;
|
|
29
|
+
return {
|
|
30
|
+
name: 'vike:pluginNonRunnableDev',
|
|
31
|
+
configureServer(viteDevServer) {
|
|
32
|
+
(0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
|
|
33
|
+
},
|
|
34
|
+
configResolved(config_) {
|
|
35
|
+
config = config_;
|
|
36
|
+
},
|
|
37
|
+
transform(code, id) {
|
|
38
|
+
if (!config._isDev)
|
|
39
|
+
return;
|
|
40
|
+
if (id !== runtimeGlobalContextFilePath)
|
|
41
|
+
return;
|
|
42
|
+
const isNonRunnableDev = !(0, utils_js_1.isRunnableDevEnvironment)(this.environment);
|
|
43
|
+
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
44
|
+
if (isNonRunnableDev) {
|
|
45
|
+
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
46
|
+
}
|
|
47
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(isNonRunnableDev));
|
|
48
|
+
return getMagicStringResult();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -26,7 +26,7 @@ function pluginReplaceConstants() {
|
|
|
26
26
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
27
27
|
if (!id.startsWith(config.root))
|
|
28
28
|
return;
|
|
29
|
-
if (!code.includes('
|
|
29
|
+
if (!code.includes('({}).'))
|
|
30
30
|
return;
|
|
31
31
|
const isBuild = config.command === 'build';
|
|
32
32
|
(0, utils_js_1.assert)(isBuild);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfigValueSourcesRelevant = getConfigValueSourcesRelevant;
|
|
4
|
+
exports.isRuntimeEnvMatch = isRuntimeEnvMatch;
|
|
5
|
+
const utils_js_1 = require("../../utils.js");
|
|
6
|
+
function getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig) {
|
|
7
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
8
|
+
(0, utils_js_1.assert)(configDef);
|
|
9
|
+
let sourcesRelevant = pageConfig.configValueSources[configName];
|
|
10
|
+
if (!sourcesRelevant)
|
|
11
|
+
return [];
|
|
12
|
+
if (!configDef.cumulative) {
|
|
13
|
+
const source = sourcesRelevant[0];
|
|
14
|
+
if (source) {
|
|
15
|
+
sourcesRelevant = [source];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, utils_js_1.assert)(sourcesRelevant.length === 0);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// isOverridden() must be called before isRuntimeEnvMatch() is called (otherwise isOverridden() will return a wrong value)
|
|
23
|
+
sourcesRelevant = sourcesRelevant.filter((source) => !isOverridden(source, configName, pageConfig));
|
|
24
|
+
}
|
|
25
|
+
sourcesRelevant = sourcesRelevant.filter((source) => isRuntimeEnvMatch(source.configEnv, runtimeEnv));
|
|
26
|
+
return sourcesRelevant;
|
|
27
|
+
}
|
|
28
|
+
function isRuntimeEnvMatch(configEnv, runtimeEnv) {
|
|
29
|
+
if ('isForConfig' in runtimeEnv)
|
|
30
|
+
return !!configEnv.config;
|
|
31
|
+
// Runtime
|
|
32
|
+
if (!runtimeEnv.isForClientSide) {
|
|
33
|
+
if (!configEnv.server)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (!configEnv.client)
|
|
38
|
+
return false;
|
|
39
|
+
if (configEnv.client === 'if-client-routing' && !runtimeEnv.isClientRouting)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// Production/development
|
|
43
|
+
if (configEnv.production !== undefined) {
|
|
44
|
+
(0, utils_js_1.assert)(typeof configEnv.production === 'boolean');
|
|
45
|
+
(0, utils_js_1.assert)(typeof runtimeEnv.isDev === 'boolean');
|
|
46
|
+
if (configEnv.production) {
|
|
47
|
+
if (runtimeEnv.isDev)
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
if (!runtimeEnv.isDev)
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
function isOverridden(source, configName, pageConfig) {
|
|
58
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
59
|
+
(0, utils_js_1.assert)(configDef);
|
|
60
|
+
if (configDef.cumulative)
|
|
61
|
+
return false;
|
|
62
|
+
const sources = pageConfig.configValueSources[configName];
|
|
63
|
+
(0, utils_js_1.assert)(sources);
|
|
64
|
+
const idx = sources.indexOf(source);
|
|
65
|
+
(0, utils_js_1.assert)(idx >= 0);
|
|
66
|
+
return idx > 0;
|
|
67
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVirtualFilePageConfigLazy = getVirtualFilePageConfigLazy;
|
|
4
|
+
// TODO/now: rename file to generateVirtualFileEntryPage.ts
|
|
4
5
|
const utils_js_1 = require("../../utils.js");
|
|
5
6
|
const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
6
7
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
7
8
|
const extractAssetsQuery_js_1 = require("../../../shared/extractAssetsQuery.js");
|
|
8
9
|
const debug_js_1 = require("./debug.js");
|
|
9
|
-
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
10
10
|
const serializeConfigValues_js_1 = require("../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
11
11
|
const handleAssetsManifest_js_1 = require("../pluginBuild/handleAssetsManifest.js");
|
|
12
12
|
const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
@@ -45,7 +45,7 @@ function getLoadConfigLazy(pageConfig, isForClientSide, pageId, includeAssetsImp
|
|
|
45
45
|
const filesEnv = new Map();
|
|
46
46
|
const isClientRouting = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
47
47
|
lines.push('export const configValuesSerialized = {');
|
|
48
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv,
|
|
48
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, '', false));
|
|
49
49
|
lines.push('};');
|
|
50
50
|
if (!(0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(config) && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
51
51
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigLazy_js_1.getVirtualFileIdPageConfigLazy)(pageId, false))}'`);
|
|
@@ -4,7 +4,6 @@ exports.getVirtualFilePageConfigsEager = getVirtualFilePageConfigsEager;
|
|
|
4
4
|
const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
5
5
|
const debug_js_1 = require("./debug.js");
|
|
6
6
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
7
|
-
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
8
7
|
const serializeConfigValues_js_1 = require("../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
9
8
|
async function getVirtualFilePageConfigsEager(isForClientSide, isDev, id, isClientRouting) {
|
|
10
9
|
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)(true);
|
|
@@ -21,6 +20,10 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
21
20
|
lines.push('export const pageConfigGlobalSerialized = {');
|
|
22
21
|
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
|
|
23
22
|
lines.push('};');
|
|
23
|
+
if (!isForClientSide && isDev) {
|
|
24
|
+
// https://vite.dev/guide/api-environment-frameworks.html
|
|
25
|
+
lines.push('if ((undefined)) (undefined).accept();');
|
|
26
|
+
}
|
|
24
27
|
const code = [...importStatements, ...lines].join('\n');
|
|
25
28
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
26
29
|
return code;
|
|
@@ -37,7 +40,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
37
40
|
const load = `() => ({ moduleId: ${virtualFileId}, moduleExports: import(${virtualFileId}) })`;
|
|
38
41
|
lines.push(` loadConfigLazy: ${load},`);
|
|
39
42
|
lines.push(` configValuesSerialized: {`);
|
|
40
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv,
|
|
43
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', true));
|
|
41
44
|
lines.push(` },`);
|
|
42
45
|
lines.push(` },`);
|
|
43
46
|
});
|
|
@@ -47,7 +50,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
47
50
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv) {
|
|
48
51
|
const lines = [];
|
|
49
52
|
lines.push(` configValuesSerialized: {`);
|
|
50
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, filesEnv,
|
|
53
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', null));
|
|
51
54
|
lines.push(` },`);
|
|
52
55
|
const code = lines.join('\n');
|
|
53
56
|
return code;
|
|
@@ -8,7 +8,6 @@ const vite_1 = require("vite");
|
|
|
8
8
|
const getVirtualFilePageConfigLazy_js_1 = require("./pluginVirtualFiles/getVirtualFilePageConfigLazy.js");
|
|
9
9
|
const getVirtualFileEntry_js_1 = require("./pluginVirtualFiles/getVirtualFileEntry.js");
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
|
-
const virtualFiles_js_1 = require("../../shared/virtualFiles.js");
|
|
12
11
|
const virtualFilePageConfigLazy_js_1 = require("../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
13
12
|
const virtualFileEntry_js_1 = require("../../shared/virtualFiles/virtualFileEntry.js");
|
|
14
13
|
const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInternal.js");
|
|
@@ -30,8 +29,8 @@ function pluginVirtualFiles() {
|
|
|
30
29
|
config.experimental.importGlobRestoreExtension = true;
|
|
31
30
|
},
|
|
32
31
|
resolveId(id) {
|
|
33
|
-
if ((0,
|
|
34
|
-
return (0,
|
|
32
|
+
if ((0, utils_js_1.isVirtualFileId)(id)) {
|
|
33
|
+
return (0, utils_js_1.addVirtualFileIdPrefix)(id);
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
async handleHotUpdate(ctx) {
|
|
@@ -45,9 +44,9 @@ function pluginVirtualFiles() {
|
|
|
45
44
|
}
|
|
46
45
|
},
|
|
47
46
|
async load(id, options) {
|
|
48
|
-
if (!(0,
|
|
47
|
+
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
49
48
|
return undefined;
|
|
50
|
-
id = (0,
|
|
49
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
51
50
|
const isDev = config._isDev;
|
|
52
51
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
53
52
|
if ((0, virtualFilePageConfigLazy_js_1.isVirtualFileIdPageConfigLazy)(id)) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyRegExpWithMagicString = applyRegExpWithMagicString;
|
|
4
|
+
// TODO/now: replace with .replaceAll() ?
|
|
4
5
|
function applyRegExpWithMagicString(magicString, regExp, replacement) {
|
|
5
6
|
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
|
|
6
7
|
let match;
|
|
@@ -0,0 +1,18 @@
|
|
|
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.getMagicString = getMagicString;
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
|
+
// TODO/now use everywhere
|
|
9
|
+
function getMagicString(code, id) {
|
|
10
|
+
const magicString = new magic_string_1.default(code);
|
|
11
|
+
const getMagicStringResult = () => {
|
|
12
|
+
return {
|
|
13
|
+
code: magicString.toString(),
|
|
14
|
+
map: magicString.generateMap({ hires: true, source: id }),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
return { magicString, getMagicStringResult };
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getManifestFilePathRelative = getManifestFilePathRelative;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
function getManifestFilePathRelative(manifestConfig) {
|
|
6
|
+
(0, utils_js_1.assert)(['string', 'boolean'].includes(typeof manifestConfig));
|
|
7
|
+
(0, utils_js_1.assert)(manifestConfig !== false);
|
|
8
|
+
const manifestFileRelative = typeof manifestConfig === 'string' ? manifestConfig : '.vite/manifest.json';
|
|
9
|
+
return manifestFileRelative;
|
|
10
|
+
}
|