vike 0.4.216 → 0.4.217
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/api/build.js +4 -2
- package/dist/cjs/node/api/prepareViteApiCall.js +14 -4
- package/dist/cjs/node/plugin/index.js +5 -7
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/cjs/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +9 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +128 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +40 -26
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -3
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +4 -1
- package/dist/cjs/node/prerender/runPrerender.js +2 -4
- package/dist/cjs/node/runtime/globalContext.js +16 -8
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/cjs/node/shared/resolveBase.js +41 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/api/build.js +4 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +1 -1
- package/dist/esm/node/api/prepareViteApiCall.js +14 -4
- package/dist/esm/node/plugin/index.d.ts +3 -3
- package/dist/esm/node/plugin/index.js +3 -5
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -12
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +17 -12
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +15 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -7
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/{shared/ConfigVike.d.ts → node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts} +14 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +41 -27
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +4 -3
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +5 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -4
- package/dist/esm/node/runtime/globalContext.d.ts +6 -2
- package/dist/esm/node/runtime/globalContext.js +16 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/shared/resolveBase.d.ts +11 -0
- package/dist/esm/node/shared/resolveBase.js +36 -0
- package/dist/esm/shared/page-configs/Config.d.ts +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +0 -75
- package/dist/cjs/node/plugin/plugins/config/index.js +0 -81
- package/dist/cjs/node/plugin/plugins/config/pickFirst.js +0 -6
- package/dist/cjs/node/plugin/plugins/config/resolveBase.js +0 -47
- package/dist/cjs/node/shared/getConfigVike.js +0 -10
- package/dist/cjs/shared/ConfigVike.js +0 -2
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.d.ts +0 -7
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +0 -73
- package/dist/esm/node/plugin/plugins/config/index.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +0 -76
- package/dist/esm/node/plugin/plugins/config/pickFirst.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/config/pickFirst.js +0 -3
- package/dist/esm/node/plugin/plugins/config/resolveBase.d.ts +0 -10
- package/dist/esm/node/plugin/plugins/config/resolveBase.js +0 -42
- package/dist/esm/node/shared/getConfigVike.d.ts +0 -4
- package/dist/esm/node/shared/getConfigVike.js +0 -8
- package/dist/esm/shared/ConfigVike.js +0 -1
|
@@ -12,7 +12,6 @@ import { devConfig } from './plugins/devConfig/index.js';
|
|
|
12
12
|
import { packageJsonFile } from './plugins/packageJsonFile.js';
|
|
13
13
|
import { removeRequireHookPlugin } from './plugins/removeRequireHookPlugin.js';
|
|
14
14
|
import { importUserCode } from './plugins/importUserCode/index.js';
|
|
15
|
-
import { resolveVikeConfig } from './plugins/config/index.js';
|
|
16
15
|
import { distFileNames } from './plugins/distFileNames.js';
|
|
17
16
|
import { extractAssetsPlugin } from './plugins/extractAssetsPlugin.js';
|
|
18
17
|
import { extractExportNamesPlugin } from './plugins/extractExportNamesPlugin.js';
|
|
@@ -32,10 +31,9 @@ markSetup_vikeVitePlugin();
|
|
|
32
31
|
assertViteVersion();
|
|
33
32
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
34
33
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
35
|
-
function plugin(
|
|
34
|
+
function plugin(vikeVitePluginOptions) {
|
|
36
35
|
const plugins = [
|
|
37
|
-
|
|
38
|
-
...commonConfig(),
|
|
36
|
+
...commonConfig(vikeVitePluginOptions),
|
|
39
37
|
importUserCode(),
|
|
40
38
|
...devConfig(),
|
|
41
39
|
...buildConfig(),
|
|
@@ -49,7 +47,7 @@ function plugin(vikeConfig) {
|
|
|
49
47
|
suppressRollupWarning(),
|
|
50
48
|
...setGlobalContext(),
|
|
51
49
|
...importBuild(),
|
|
52
|
-
baseUrls(
|
|
50
|
+
baseUrls(vikeVitePluginOptions),
|
|
53
51
|
envVarsPlugin(),
|
|
54
52
|
fileEnv(),
|
|
55
53
|
workaroundCssModuleHmr(),
|
|
@@ -3,24 +3,25 @@ export { autoFullBuild };
|
|
|
3
3
|
import { build } from 'vite';
|
|
4
4
|
import { assertWarning } from '../utils.js';
|
|
5
5
|
import { runPrerenderFromAutoRun, runPrerender_forceExit } from '../../prerender/runPrerender.js';
|
|
6
|
-
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
7
6
|
import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
|
|
8
7
|
import pc from '@brillout/picocolors';
|
|
9
8
|
import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
|
|
10
9
|
import { manifestTempFile } from './buildConfig.js';
|
|
10
|
+
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
11
11
|
let forceExit = false;
|
|
12
12
|
function autoFullBuild() {
|
|
13
13
|
let config;
|
|
14
|
-
let
|
|
14
|
+
let vikeConfigGlobal;
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
17
|
name: 'vike:autoFullBuild',
|
|
18
18
|
apply: 'build',
|
|
19
19
|
enforce: 'pre',
|
|
20
20
|
async configResolved(config_) {
|
|
21
|
-
|
|
21
|
+
const vikeConfig = await getVikeConfig(config_);
|
|
22
|
+
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
22
23
|
config = config_;
|
|
23
|
-
abortViteBuildSsr(
|
|
24
|
+
abortViteBuildSsr(vikeConfigGlobal);
|
|
24
25
|
},
|
|
25
26
|
writeBundle: {
|
|
26
27
|
/* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
|
|
@@ -29,7 +30,7 @@ function autoFullBuild() {
|
|
|
29
30
|
*/
|
|
30
31
|
async handler(_options, bundle) {
|
|
31
32
|
try {
|
|
32
|
-
await triggerFullBuild(config,
|
|
33
|
+
await triggerFullBuild(config, vikeConfigGlobal, bundle);
|
|
33
34
|
}
|
|
34
35
|
catch (err) {
|
|
35
36
|
// Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
@@ -55,10 +56,10 @@ function autoFullBuild() {
|
|
|
55
56
|
}
|
|
56
57
|
];
|
|
57
58
|
}
|
|
58
|
-
async function triggerFullBuild(config,
|
|
59
|
+
async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
|
|
59
60
|
if (config.build.ssr)
|
|
60
61
|
return; // already triggered
|
|
61
|
-
if (isDisabled(
|
|
62
|
+
if (isDisabled(vikeConfigGlobal))
|
|
62
63
|
return;
|
|
63
64
|
// Workaround for @vitejs/plugin-legacy
|
|
64
65
|
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
@@ -89,19 +90,21 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
89
90
|
logErrorHint(err);
|
|
90
91
|
process.exit(1);
|
|
91
92
|
}
|
|
92
|
-
if (
|
|
93
|
+
if (vikeConfigGlobal.prerender &&
|
|
94
|
+
!vikeConfigGlobal.prerender.disableAutoRun &&
|
|
95
|
+
vikeConfigGlobal.disableAutoFullBuild !== 'prerender') {
|
|
93
96
|
await runPrerenderFromAutoRun(configInline, false);
|
|
94
97
|
forceExit = true;
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
|
-
function abortViteBuildSsr(
|
|
98
|
-
if (
|
|
100
|
+
function abortViteBuildSsr(vikeConfigGlobal) {
|
|
101
|
+
if (vikeConfigGlobal.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
99
102
|
assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
|
|
100
103
|
process.exit(0);
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
|
-
function isDisabled(
|
|
104
|
-
const { disableAutoFullBuild } =
|
|
106
|
+
function isDisabled(vikeConfigGlobal) {
|
|
107
|
+
const { disableAutoFullBuild } = vikeConfigGlobal;
|
|
105
108
|
if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
|
|
106
109
|
return !isViteCliCall();
|
|
107
110
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
2
|
import type { Plugin } from 'vite';
|
|
3
|
-
import type {
|
|
4
|
-
declare function baseUrls(
|
|
3
|
+
import type { VikeVitePluginOptions } from './importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
|
|
4
|
+
declare function baseUrls(vikeVitePluginOptions?: VikeVitePluginOptions): Plugin;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
|
-
import {
|
|
2
|
+
import { resolveBase, resolveBaseFromResolvedConfig } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
|
-
import {
|
|
5
|
-
function baseUrls(
|
|
6
|
-
let
|
|
7
|
-
let baseAssets;
|
|
4
|
+
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
|
+
function baseUrls(vikeVitePluginOptions) {
|
|
6
|
+
let bases;
|
|
8
7
|
return {
|
|
9
8
|
name: 'vike:baseUrls',
|
|
10
9
|
enforce: 'post',
|
|
11
10
|
async config(config) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
baseAssets = bases
|
|
11
|
+
// TODO: fix bug: use getVikeConfig2() and udpate check below
|
|
12
|
+
bases = resolveBaseFromUserConfig(config, vikeVitePluginOptions);
|
|
13
|
+
const { baseServer, baseAssets } = bases;
|
|
15
14
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
16
15
|
process.env.BASE_SERVER = baseServer;
|
|
17
16
|
process.env.BASE_ASSETS = baseAssets;
|
|
@@ -22,14 +21,16 @@ function baseUrls(configVike) {
|
|
|
22
21
|
'BASE_ASSETS'
|
|
23
22
|
],
|
|
24
23
|
base: baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
|
|
25
|
-
|
|
24
|
+
_baseViteOriginal: config.base ?? '/__UNSET__' // Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
26
25
|
};
|
|
27
26
|
},
|
|
28
27
|
async configResolved(config) {
|
|
29
|
-
const
|
|
28
|
+
const vikeConfig = await getVikeConfig(config);
|
|
29
|
+
const { baseServer, baseAssets } = vikeConfig.vikeConfigGlobal;
|
|
30
|
+
const basesResolved = resolveBaseFromResolvedConfig(baseServer, baseAssets, config);
|
|
30
31
|
// Ensure that the premature base URL resolving we did in config() isn't erroneous
|
|
31
|
-
assert(
|
|
32
|
-
assert(
|
|
32
|
+
assert(basesResolved.baseServer === bases.baseServer);
|
|
33
|
+
assert(basesResolved.baseAssets === bases.baseAssets);
|
|
33
34
|
/* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
|
|
34
35
|
* - In dev, Vite removes the URL origin. (I.e. it resolves the user config `vite.config.js#base: 'http://localhost:8080/cdn/'` to resolved config `config.base === '/cdn/'`.)
|
|
35
36
|
* - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
|
|
@@ -38,3 +39,7 @@ function baseUrls(configVike) {
|
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
41
|
}
|
|
42
|
+
function resolveBaseFromUserConfig(config, vikeVitePluginOptions) {
|
|
43
|
+
const baseViteOriginal = config.base ?? null;
|
|
44
|
+
return resolveBase(baseViteOriginal, vikeVitePluginOptions?.baseServer ?? null, vikeVitePluginOptions?.baseAssets ?? null);
|
|
45
|
+
}
|
|
@@ -202,7 +202,7 @@ function fixServerAssets_assertCssTarget_populate(config) {
|
|
|
202
202
|
async function fixServerAssets_assertCssTarget(config) {
|
|
203
203
|
if (!fixServerAssets_isEnabled())
|
|
204
204
|
return;
|
|
205
|
-
if (!(await isV1Design(config
|
|
205
|
+
if (!(await isV1Design(config)))
|
|
206
206
|
return;
|
|
207
207
|
const targetsServer = targets.filter((t) => t.isServerSide);
|
|
208
208
|
const targetsClient = targets.filter((t) => !t.isServerSide);
|
|
@@ -5,7 +5,6 @@ export { manifestTempFile };
|
|
|
5
5
|
import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, onSetupBuild, assertIsNpmPackageImport } from '../utils.js';
|
|
6
6
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { findPageFiles } from '../shared/findPageFiles.js';
|
|
8
|
-
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
9
8
|
import { getVirtualFileIdPageConfigValuesAll } from '../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
10
9
|
import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
11
10
|
import { createRequire } from 'module';
|
|
@@ -42,7 +41,7 @@ function buildConfig() {
|
|
|
42
41
|
addLogHook();
|
|
43
42
|
outDirs = getOutDirs(config);
|
|
44
43
|
{
|
|
45
|
-
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config
|
|
44
|
+
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config));
|
|
46
45
|
if (isServerAssetsFixEnabled) {
|
|
47
46
|
// https://github.com/vikejs/vike/issues/1339
|
|
48
47
|
config.build.ssrEmitAssets = true;
|
|
@@ -111,9 +110,9 @@ function buildConfig() {
|
|
|
111
110
|
];
|
|
112
111
|
}
|
|
113
112
|
async function getEntries(config) {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const
|
|
113
|
+
const vikeConfig = await getVikeConfig(config);
|
|
114
|
+
const { pageConfigs } = vikeConfig;
|
|
115
|
+
const pageFileEntries = await getPageFileEntries(config, vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer); // TODO/v1-release: remove
|
|
117
116
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
118
117
|
if (viteIsSSR(config)) {
|
|
119
118
|
const pageEntries = getPageEntries(pageConfigs);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
2
|
import { mergeConfig } from 'vite';
|
|
3
|
-
import { assert, assertUsage, assertWarning, findPackageJson, isDocker } from '../utils.js';
|
|
3
|
+
import { assert, assertUsage, assertWarning, findPackageJson, isDevCheck, isDocker } from '../utils.js';
|
|
4
4
|
import { assertRollupInput } from './buildConfig.js';
|
|
5
5
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
@@ -10,8 +10,21 @@ import { pluginName } from './commonConfig/pluginName.js';
|
|
|
10
10
|
import { getEnvVarObject } from '../shared/getEnvVarObject.js';
|
|
11
11
|
import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
12
12
|
import { isVikeCliOrApi } from '../../api/context.js';
|
|
13
|
-
function commonConfig() {
|
|
13
|
+
function commonConfig(vikeVitePluginOptions = {}) {
|
|
14
14
|
return [
|
|
15
|
+
{
|
|
16
|
+
name: `${pluginName}:pre`,
|
|
17
|
+
enforce: 'pre',
|
|
18
|
+
config: {
|
|
19
|
+
order: 'pre',
|
|
20
|
+
handler(_config, env) {
|
|
21
|
+
return {
|
|
22
|
+
_isDev: isDevCheck(env),
|
|
23
|
+
_vikeVitePluginOptions: vikeVitePluginOptions
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
15
28
|
{
|
|
16
29
|
name: pluginName,
|
|
17
30
|
configResolved(config) {
|
|
@@ -6,9 +6,9 @@ import { analyzeClientEntries } from '../buildConfig.js';
|
|
|
6
6
|
import { virtualFileIdImportUserCodeClientCR, virtualFileIdImportUserCodeClientSR } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
7
7
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
8
8
|
const debug = createDebugger('vike:optimizeDeps');
|
|
9
|
-
async function determineOptimizeDeps(config
|
|
10
|
-
const { pageConfigs } = await getVikeConfig(config
|
|
11
|
-
const { entries, include } = await getPageDeps(config, pageConfigs
|
|
9
|
+
async function determineOptimizeDeps(config) {
|
|
10
|
+
const { pageConfigs } = await getVikeConfig(config);
|
|
11
|
+
const { entries, include } = await getPageDeps(config, pageConfigs);
|
|
12
12
|
{
|
|
13
13
|
// This actually doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
14
14
|
// - Should we make it work? E.g. by creating a temporary file at node_modules/.vike/virtualFiles.js
|
|
@@ -28,7 +28,7 @@ async function determineOptimizeDeps(config, isDev) {
|
|
|
28
28
|
'config.optimizeDeps.include': config.optimizeDeps.include
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
async function getPageDeps(config, pageConfigs
|
|
31
|
+
async function getPageDeps(config, pageConfigs) {
|
|
32
32
|
let entries = [];
|
|
33
33
|
let include = [];
|
|
34
34
|
const addEntry = (e) => {
|
|
@@ -67,7 +67,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
67
67
|
}
|
|
68
68
|
// V0.4 design
|
|
69
69
|
{
|
|
70
|
-
const pageFiles = await findPageFiles(config, ['.page', '.page.client'],
|
|
70
|
+
const pageFiles = await findPageFiles(config, ['.page', '.page.client'], true);
|
|
71
71
|
const userRootDir = config.root;
|
|
72
72
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
73
73
|
const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
@@ -58,7 +58,7 @@ function devConfig() {
|
|
|
58
58
|
},
|
|
59
59
|
async configResolved(config_) {
|
|
60
60
|
config = config_;
|
|
61
|
-
await determineOptimizeDeps(config
|
|
61
|
+
await determineOptimizeDeps(config);
|
|
62
62
|
await determineFsAllowList(config);
|
|
63
63
|
if (!isErrorDebug()) {
|
|
64
64
|
await installHttpRequestAsyncStore();
|
|
@@ -9,7 +9,6 @@ export { extractAssetsRE };
|
|
|
9
9
|
import { viteIsSSR_options, assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage } from '../utils.js';
|
|
10
10
|
import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../shared/virtual-files.js';
|
|
11
11
|
import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
12
|
-
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
13
12
|
import { isAsset } from '../shared/isAsset.js';
|
|
14
13
|
import { getImportStatements } from '../shared/parseEsModule.js';
|
|
15
14
|
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
@@ -25,7 +24,6 @@ const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
|
25
24
|
const debug = createDebugger('vike:extractAssets');
|
|
26
25
|
function extractAssetsPlugin() {
|
|
27
26
|
let config;
|
|
28
|
-
let configVike;
|
|
29
27
|
let vikeConfig;
|
|
30
28
|
let isServerAssetsFixEnabled;
|
|
31
29
|
return [
|
|
@@ -45,7 +43,7 @@ function extractAssetsPlugin() {
|
|
|
45
43
|
assertV1Design(vikeConfig.pageConfigs, true);
|
|
46
44
|
assert(false);
|
|
47
45
|
}
|
|
48
|
-
assert(
|
|
46
|
+
assert(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
|
|
49
47
|
assert(!viteIsSSR_options(options));
|
|
50
48
|
const importStatements = await getImportStatements(src);
|
|
51
49
|
const moduleNames = getImportedModules(importStatements);
|
|
@@ -78,7 +76,7 @@ function extractAssetsPlugin() {
|
|
|
78
76
|
if (!extractAssetsRE.test(importer)) {
|
|
79
77
|
return;
|
|
80
78
|
}
|
|
81
|
-
assert(
|
|
79
|
+
assert(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
|
|
82
80
|
let resolution = null;
|
|
83
81
|
try {
|
|
84
82
|
resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
|
|
@@ -137,10 +135,9 @@ function extractAssetsPlugin() {
|
|
|
137
135
|
{
|
|
138
136
|
name: 'vike:extractAssets-4',
|
|
139
137
|
async configResolved(config_) {
|
|
140
|
-
configVike = await getConfigVike(config_);
|
|
141
138
|
config = config_;
|
|
142
|
-
vikeConfig = await getVikeConfig(config
|
|
143
|
-
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config
|
|
139
|
+
vikeConfig = await getVikeConfig(config);
|
|
140
|
+
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config));
|
|
144
141
|
if (!isServerAssetsFixEnabled) {
|
|
145
142
|
// https://github.com/vikejs/vike/issues/1060
|
|
146
143
|
assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getVikeManifest };
|
|
2
2
|
import { type PluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { VikeConfigGlobal } from '../importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
|
|
4
|
+
import type { ResolvedConfig } from 'vite';
|
|
5
|
+
declare function getVikeManifest(vikeConfigGlobal: VikeConfigGlobal, viteConfig: ResolvedConfig): PluginManifest;
|
|
@@ -3,8 +3,8 @@ import { projectInfo } from '../../utils.js';
|
|
|
3
3
|
import { assertPluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
4
4
|
import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
|
|
5
5
|
import { getRuntimeManifest } from '../../../runtime/globalContext.js';
|
|
6
|
-
function getVikeManifest(
|
|
7
|
-
const runtimeManifest = getRuntimeManifest(
|
|
6
|
+
function getVikeManifest(vikeConfigGlobal, viteConfig) {
|
|
7
|
+
const runtimeManifest = getRuntimeManifest(vikeConfigGlobal, viteConfig);
|
|
8
8
|
const manifest = {
|
|
9
9
|
version: projectInfo.projectVersion,
|
|
10
10
|
usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
|
|
@@ -4,37 +4,39 @@ import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/
|
|
|
4
4
|
import { assert, getOutDirs, toPosixPath } from '../../utils.js';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
|
-
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
8
7
|
import { getVikeManifest } from './getVikeManifest.js';
|
|
9
8
|
import fs from 'fs/promises';
|
|
10
9
|
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
10
|
+
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
11
11
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
12
12
|
const importMetaUrl = import.meta.url;
|
|
13
13
|
const require_ = createRequire(importMetaUrl);
|
|
14
14
|
const ASSETS_MAP = '__VITE_ASSETS_MAP__';
|
|
15
15
|
function importBuild() {
|
|
16
16
|
let config;
|
|
17
|
-
let
|
|
17
|
+
let vikeConfigGlobal;
|
|
18
18
|
return [
|
|
19
19
|
{
|
|
20
20
|
name: 'vike:importBuild:config',
|
|
21
21
|
enforce: 'post',
|
|
22
22
|
async configResolved(config_) {
|
|
23
23
|
config = config_;
|
|
24
|
-
|
|
24
|
+
const vikeConfig = await getVikeConfig(config);
|
|
25
|
+
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
...serverProductionEntryPlugin({
|
|
28
29
|
getServerProductionEntry: () => {
|
|
29
|
-
return getServerProductionEntryCode(config,
|
|
30
|
+
return getServerProductionEntryCode(config, vikeConfigGlobal);
|
|
30
31
|
},
|
|
31
32
|
libraryName: 'Vike'
|
|
32
33
|
})
|
|
33
34
|
];
|
|
34
35
|
}
|
|
35
|
-
function getServerProductionEntryCode(config,
|
|
36
|
+
function getServerProductionEntryCode(config, vikeConfigGlobal) {
|
|
36
37
|
const importPath = getImportPath(config);
|
|
37
|
-
const vikeManifest = getVikeManifest(
|
|
38
|
+
const vikeManifest = getVikeManifest(vikeConfigGlobal, config);
|
|
39
|
+
// Let's eventually simplify and move everything to a single virtual module
|
|
38
40
|
const importerCode = [
|
|
39
41
|
` import { setImportBuildGetters } from '${importPath}';`,
|
|
40
42
|
` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
2
|
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VikeConfigGlobal } from './v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
|
|
4
4
|
declare function getVirtualFileImportUserCode(id: string, options: {
|
|
5
5
|
ssr?: boolean;
|
|
6
|
-
} | undefined,
|
|
6
|
+
} | undefined, vikeConfigGlobal: VikeConfigGlobal, config: ResolvedConfig, isDev: boolean): Promise<string>;
|
|
@@ -6,16 +6,16 @@ import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { getVirtualFilePageConfigs } from './v1-design/getVirtualFilePageConfigs.js';
|
|
8
8
|
import { isV1Design as isV1Design_ } from './v1-design/getVikeConfig.js';
|
|
9
|
-
async function getVirtualFileImportUserCode(id, options,
|
|
9
|
+
async function getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev) {
|
|
10
10
|
const idParsed = isVirtualFileIdImportUserCode(id);
|
|
11
11
|
assert(idParsed);
|
|
12
12
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
13
13
|
assert(isForClientSide === !viteIsSSR_options(options));
|
|
14
|
-
const isPrerendering = !!
|
|
15
|
-
const code = await getCode(config,
|
|
14
|
+
const isPrerendering = !!vikeConfigGlobal.prerender;
|
|
15
|
+
const code = await getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id);
|
|
16
16
|
return code;
|
|
17
17
|
}
|
|
18
|
-
async function getCode(config,
|
|
18
|
+
async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
|
|
19
19
|
const { command } = config;
|
|
20
20
|
assert(command === 'serve' || command === 'build');
|
|
21
21
|
const isBuild = command === 'build';
|
|
@@ -24,7 +24,7 @@ async function getCode(config, configVike, isForClientSide, isClientRouting, isP
|
|
|
24
24
|
{
|
|
25
25
|
const globRoots = getGlobRoots(config);
|
|
26
26
|
debugGlob('Glob roots: ', globRoots);
|
|
27
|
-
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
27
|
+
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id);
|
|
28
28
|
}
|
|
29
29
|
debugGlob(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
30
30
|
return content;
|
|
@@ -54,7 +54,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting,
|
|
57
|
+
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id) {
|
|
58
58
|
let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
|
|
59
59
|
|
|
60
60
|
export const pageFilesLazy = {};
|
|
@@ -68,7 +68,7 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
|
|
|
68
68
|
|
|
69
69
|
`;
|
|
70
70
|
// We still use import.meta.glob() when using th V1 design in order to not break the V1 design deprecation warning
|
|
71
|
-
const isV1Design = await isV1Design_(config
|
|
71
|
+
const isV1Design = await isV1Design_(config);
|
|
72
72
|
fileTypes
|
|
73
73
|
.filter((fileType) => fileType !== '.css')
|
|
74
74
|
.forEach((fileType) => {
|
|
@@ -86,7 +86,7 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
|
|
|
86
86
|
fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
-
if (
|
|
89
|
+
if (vikeConfigGlobal.includeAssetsImportedByServer && isForClientSide) {
|
|
90
90
|
fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
|
|
91
91
|
}
|
|
92
92
|
return fileContent;
|
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
export { importUserCode };
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
|
-
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
3
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
4
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath
|
|
5
|
+
import { assert, assertPosixPath } from '../../utils.js';
|
|
7
6
|
import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../../shared/virtual-files.js';
|
|
8
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
9
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
10
|
-
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile, isV1Design } from './v1-design/getVikeConfig.js';
|
|
9
|
+
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile, isV1Design, getVikeConfig } from './v1-design/getVikeConfig.js';
|
|
11
10
|
import pc from '@brillout/picocolors';
|
|
12
11
|
import { logConfigInfo } from '../../shared/loggerNotProd.js';
|
|
13
12
|
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
14
13
|
function importUserCode() {
|
|
15
14
|
let config;
|
|
16
|
-
let
|
|
17
|
-
let isDev;
|
|
15
|
+
let vikeConfigGlobal;
|
|
18
16
|
return {
|
|
19
17
|
name: 'vike:importUserCode',
|
|
20
|
-
config(_, env) {
|
|
21
|
-
isDev = isDevCheck(env);
|
|
22
|
-
},
|
|
23
18
|
async configResolved(config_) {
|
|
24
|
-
|
|
19
|
+
const vikeConfig = await getVikeConfig(config_);
|
|
20
|
+
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
25
21
|
config = config_;
|
|
26
22
|
// TODO/v1-release: remove
|
|
27
23
|
{
|
|
28
|
-
|
|
29
|
-
const isV1 = await isV1Design(config, isDev);
|
|
24
|
+
const isV1 = await isV1Design(config);
|
|
30
25
|
if (!isV1)
|
|
31
26
|
config.experimental.importGlobRestoreExtension = true;
|
|
32
27
|
}
|
|
@@ -50,13 +45,14 @@ function importUserCode() {
|
|
|
50
45
|
if (!isVirtualFileId(id))
|
|
51
46
|
return undefined;
|
|
52
47
|
id = getVirtualFileId(id);
|
|
48
|
+
const isDev = config._isDev;
|
|
53
49
|
assert(typeof isDev === 'boolean');
|
|
54
50
|
if (isVirtualFileIdPageConfigValuesAll(id)) {
|
|
55
51
|
const code = await getVirtualFilePageConfigValuesAll(id, isDev, config);
|
|
56
52
|
return code;
|
|
57
53
|
}
|
|
58
54
|
if (isVirtualFileIdImportUserCode(id)) {
|
|
59
|
-
const code = await getVirtualFileImportUserCode(id, options,
|
|
55
|
+
const code = await getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev);
|
|
60
56
|
return code;
|
|
61
57
|
}
|
|
62
58
|
},
|
|
@@ -83,8 +79,6 @@ function handleFileAddRemove(server, config) {
|
|
|
83
79
|
}
|
|
84
80
|
function handleHotUpdate(ctx, config) {
|
|
85
81
|
const { file, server } = ctx;
|
|
86
|
-
assertPosixPath(file);
|
|
87
|
-
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
88
82
|
const isVikeConfig = isVikeConfigModule(file);
|
|
89
83
|
const isViteModule = ctx.modules.length > 0;
|
|
90
84
|
/* Should we show this?
|
|
@@ -114,6 +108,8 @@ function handleHotUpdate(ctx, config) {
|
|
|
114
108
|
}
|
|
115
109
|
}
|
|
116
110
|
function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
111
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
112
|
+
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
117
113
|
return vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
118
114
|
}
|
|
119
115
|
function reloadConfig(filePath, config, op) {
|
|
@@ -122,7 +118,7 @@ function reloadConfig(filePath, config, op) {
|
|
|
122
118
|
const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
|
|
123
119
|
logConfigInfo(msg, 'info');
|
|
124
120
|
}
|
|
125
|
-
reloadVikeConfig(config
|
|
121
|
+
reloadVikeConfig(config);
|
|
126
122
|
}
|
|
127
123
|
function getVirtualModules(server) {
|
|
128
124
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, crawlWithGit: null | boolean): Promise<{
|
|
2
|
+
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string, crawlWithGit: null | boolean): Promise<{
|
|
3
3
|
filePathAbsoluteUserRootDir: string;
|
|
4
4
|
}[]>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export type {
|
|
3
|
-
type
|
|
1
|
+
export { resolveVikeConfigGlobal };
|
|
2
|
+
export type { VikeConfigGlobal };
|
|
3
|
+
export type { VikeVitePluginOptions };
|
|
4
|
+
declare function resolveVikeConfigGlobal(vikeVitePluginOptions: unknown, pageConfigGlobalValues: Record<string, unknown>): VikeConfigGlobal;
|
|
5
|
+
type VikeConfigGlobal = {
|
|
4
6
|
prerender: false | {
|
|
5
7
|
noExtraDir: boolean;
|
|
6
8
|
parallel: boolean | number;
|
|
@@ -9,8 +11,8 @@ type ConfigVikeResolved = {
|
|
|
9
11
|
};
|
|
10
12
|
disableAutoFullBuild: boolean | 'prerender' | null;
|
|
11
13
|
includeAssetsImportedByServer: boolean;
|
|
12
|
-
baseAssets: string;
|
|
13
|
-
baseServer: string;
|
|
14
|
+
baseAssets: string | null;
|
|
15
|
+
baseServer: string | null;
|
|
14
16
|
redirects: Record<string, string>;
|
|
15
17
|
trailingSlash: boolean;
|
|
16
18
|
disableUrlNormalization: boolean;
|
|
@@ -18,7 +20,7 @@ type ConfigVikeResolved = {
|
|
|
18
20
|
git: null | boolean;
|
|
19
21
|
};
|
|
20
22
|
};
|
|
21
|
-
type
|
|
23
|
+
type VikeVitePluginOptions = {
|
|
22
24
|
/**
|
|
23
25
|
* Enable pre-rendering.
|
|
24
26
|
*
|
|
@@ -44,12 +46,12 @@ type ConfigVikeUserProvided = {
|
|
|
44
46
|
*/
|
|
45
47
|
parallel?: boolean | number;
|
|
46
48
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
* Allow only some of your pages to be pre-rendered.
|
|
50
|
+
*
|
|
51
|
+
* This setting doesn't affect the pre-rendering process: it merely suppresses the warnings when some of your pages cannot be pre-rendered.
|
|
52
|
+
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
53
55
|
partial?: boolean;
|
|
54
56
|
/**
|
|
55
57
|
* Disable the automatic initiation of the pre-rendering process when running `$ vike build`.
|