vike 0.4.226 → 0.4.227-commit-c9cc081
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/entry.js +13 -8
- package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +6 -3
- package/dist/cjs/node/plugin/plugins/build/pluginDistPackageJsonFile.js +5 -2
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +16 -3
- package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -2
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +8 -6
- package/dist/cjs/node/plugin/plugins/envVars.js +27 -16
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +12 -5
- package/dist/cjs/node/plugin/plugins/fileEnv.js +19 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/previewConfig.js +10 -6
- package/dist/cjs/node/plugin/shared/getResolvedConfig.js +6 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +1 -0
- package/dist/cjs/node/prerender/runPrerender.js +18 -17
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +2 -5
- package/dist/cjs/utils/assertSingleInstance.js +19 -4
- package/dist/esm/node/cli/entry.js +13 -8
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +6 -3
- package/dist/esm/node/plugin/plugins/build/pluginDistPackageJsonFile.js +4 -2
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +13 -3
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +14 -2
- package/dist/esm/node/plugin/plugins/devConfig/index.js +8 -6
- package/dist/esm/node/plugin/plugins/envVars.js +24 -16
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +8 -5
- package/dist/esm/node/plugin/plugins/fileEnv.js +19 -12
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/previewConfig.js +10 -6
- package/dist/esm/node/plugin/shared/getResolvedConfig.d.ts +2 -0
- package/dist/esm/node/plugin/shared/getResolvedConfig.js +3 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +1 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +1 -1
- package/dist/esm/node/prerender/runPrerender.js +18 -17
- package/dist/esm/shared/page-configs/Config.d.ts +10 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +2 -5
- package/dist/esm/utils/assertSingleInstance.js +19 -4
- package/package.json +2 -1
|
@@ -62,14 +62,19 @@ async function cmdDev() {
|
|
|
62
62
|
const startTime = performance.now();
|
|
63
63
|
try {
|
|
64
64
|
const { viteServer } = await (0, index_js_1.dev)();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
if (viteServer.httpServer) {
|
|
66
|
+
await viteServer.listen();
|
|
67
|
+
const info = viteServer.config.logger.info;
|
|
68
|
+
const startupDurationString = picocolors_1.default.dim(`ready in ${picocolors_1.default.reset(picocolors_1.default.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
|
|
69
|
+
const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
|
|
70
|
+
info(` ${picocolors_1.default.yellow(`${picocolors_1.default.bold('Vike')} v${utils_js_1.PROJECT_VERSION}`)} ${startupDurationString}\n`, {
|
|
71
|
+
clear: !hasExistingLogs
|
|
72
|
+
});
|
|
73
|
+
viteServer.printUrls();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// vike-server => middleware mode => `viteServer.httpServer === null`
|
|
77
|
+
}
|
|
73
78
|
viteServer.bindCLIShortcuts({ print: true });
|
|
74
79
|
}
|
|
75
80
|
catch (err) {
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.pluginAutoFullBuild = pluginAutoFullBuild;
|
|
7
7
|
exports.isPrerenderForceExit = isPrerenderForceExit;
|
|
8
|
+
const getResolvedConfig_js_1 = require("../../shared/getResolvedConfig.js");
|
|
8
9
|
const vite_1 = require("vite");
|
|
9
10
|
const utils_js_1 = require("../../utils.js");
|
|
10
11
|
const runPrerender_js_1 = require("../../../prerender/runPrerender.js");
|
|
@@ -20,7 +21,7 @@ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
|
20
21
|
(0, utils_js_1.assertIsSingleModuleInstance)('build/pluginAutoFullBuild.ts');
|
|
21
22
|
let forceExit = false;
|
|
22
23
|
function pluginAutoFullBuild() {
|
|
23
|
-
let
|
|
24
|
+
let vite5Config;
|
|
24
25
|
let vikeConfig;
|
|
25
26
|
return [
|
|
26
27
|
{
|
|
@@ -29,7 +30,7 @@ function pluginAutoFullBuild() {
|
|
|
29
30
|
enforce: 'pre',
|
|
30
31
|
async configResolved(config_) {
|
|
31
32
|
vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
|
|
32
|
-
|
|
33
|
+
vite5Config = config_;
|
|
33
34
|
abortViteBuildSsr(vikeConfig);
|
|
34
35
|
},
|
|
35
36
|
writeBundle: {
|
|
@@ -38,6 +39,7 @@ function pluginAutoFullBuild() {
|
|
|
38
39
|
order: 'pre',
|
|
39
40
|
*/
|
|
40
41
|
async handler(options, bundle) {
|
|
42
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
41
43
|
await (0, handleAssetsManifest_js_1.handleAssetsManifest)(config, this.environment, options, bundle);
|
|
42
44
|
await triggerFullBuild(config, vikeConfig, this.environment, bundle);
|
|
43
45
|
}
|
|
@@ -51,6 +53,7 @@ function pluginAutoFullBuild() {
|
|
|
51
53
|
sequential: true,
|
|
52
54
|
order: 'post',
|
|
53
55
|
handler() {
|
|
56
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
54
57
|
(0, utils_js_1.onSetupBuild)();
|
|
55
58
|
(0, handleAssetsManifest_js_1.handleAssetsManifest_assertUsageCssTarget)(config);
|
|
56
59
|
if (forceExit &&
|
|
@@ -95,7 +98,7 @@ async function triggerFullBuild(config, vikeConfig, viteEnv, bundle) {
|
|
|
95
98
|
// The server bulid is already called by builder.buildApp()
|
|
96
99
|
}
|
|
97
100
|
if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig)) {
|
|
98
|
-
const res = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline
|
|
101
|
+
const res = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline);
|
|
99
102
|
forceExit = res.forceExit;
|
|
100
103
|
}
|
|
101
104
|
}
|
|
@@ -9,17 +9,20 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.pluginDistPackageJsonFile = pluginDistPackageJsonFile;
|
|
12
|
+
// TODO/refactor: prefix all other plugins with `plugin` as well?
|
|
13
|
+
const getResolvedConfig_js_1 = require("../../shared/getResolvedConfig.js");
|
|
12
14
|
const rollupIsEsm_js_1 = require("../../shared/rollupIsEsm.js");
|
|
13
15
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
14
16
|
function pluginDistPackageJsonFile() {
|
|
15
|
-
let
|
|
17
|
+
let vite5Config;
|
|
16
18
|
return {
|
|
17
19
|
name: 'vike:build:pluginDistPackageJsonFile',
|
|
18
20
|
apply: 'build',
|
|
19
21
|
configResolved(config_) {
|
|
20
|
-
|
|
22
|
+
vite5Config = config_;
|
|
21
23
|
},
|
|
22
24
|
generateBundle(options, bundle) {
|
|
25
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
23
26
|
if (!(0, isViteServerBuild_js_1.isViteServerBuild)(config))
|
|
24
27
|
return;
|
|
25
28
|
const isEsm = (0, rollupIsEsm_js_1.rollupIsEsm)(options);
|
|
@@ -1,6 +1,11 @@
|
|
|
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
|
exports.pluginModuleBanner = pluginModuleBanner;
|
|
7
|
+
const getResolvedConfig_js_1 = require("../../shared/getResolvedConfig.js");
|
|
8
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
4
9
|
const utils_js_1 = require("../../utils.js");
|
|
5
10
|
const virtual_files_js_1 = require("../../../shared/virtual-files.js");
|
|
6
11
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
@@ -8,17 +13,18 @@ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
|
8
13
|
// 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).
|
|
9
14
|
const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
|
|
10
15
|
function pluginModuleBanner() {
|
|
11
|
-
let
|
|
16
|
+
let vite5Config;
|
|
12
17
|
return {
|
|
13
18
|
name: 'vike:pluginModuleBanner',
|
|
14
19
|
enforce: 'post',
|
|
15
20
|
apply: 'build',
|
|
16
21
|
configResolved(config_) {
|
|
17
|
-
|
|
22
|
+
vite5Config = config_;
|
|
18
23
|
},
|
|
19
24
|
generateBundle: {
|
|
20
25
|
order: 'post',
|
|
21
26
|
handler(_options, bundle) {
|
|
27
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
22
28
|
for (const module of Object.values(bundle)) {
|
|
23
29
|
if (module.type === 'chunk') {
|
|
24
30
|
if ((0, isViteServerBuild_js_1.isViteServerBuild)(config)) {
|
|
@@ -37,6 +43,7 @@ function pluginModuleBanner() {
|
|
|
37
43
|
transform: {
|
|
38
44
|
order: 'post',
|
|
39
45
|
handler(code, id, options) {
|
|
46
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
40
47
|
if (!(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options))
|
|
41
48
|
return;
|
|
42
49
|
if (id.startsWith('\0'))
|
|
@@ -44,7 +51,13 @@ function pluginModuleBanner() {
|
|
|
44
51
|
id = (0, virtual_files_js_1.removeVirtualIdTag)(id);
|
|
45
52
|
if (id.startsWith(config.root))
|
|
46
53
|
id = id.slice(config.root.length + 1);
|
|
47
|
-
|
|
54
|
+
const s = new magic_string_1.default(code);
|
|
55
|
+
// No need to insert a new line; Rollup formats the code and will insert a new line.
|
|
56
|
+
s.prepend(`${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); `);
|
|
57
|
+
return {
|
|
58
|
+
code: s.toString(),
|
|
59
|
+
map: s.generateMap({ hires: true, source: id })
|
|
60
|
+
};
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
};
|
|
@@ -19,6 +19,8 @@ const context_js_2 = require("../../prerender/context.js");
|
|
|
19
19
|
const resolvePrerenderConfig_js_1 = require("../../prerender/resolvePrerenderConfig.js");
|
|
20
20
|
const pluginName = 'vike:commonConfig';
|
|
21
21
|
function commonConfig(vikeVitePluginOptions) {
|
|
22
|
+
// We cache it => makes sure we only generate one object => we can mutate it at runPrerender()
|
|
23
|
+
let prerenderContext;
|
|
22
24
|
return [
|
|
23
25
|
{
|
|
24
26
|
name: `${pluginName}:pre`,
|
|
@@ -31,6 +33,15 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
31
33
|
const root = configFromUser.root ? (0, prepareViteApiCall_js_1.normalizeViteRoot)(configFromUser.root) : await (0, prepareViteApiCall_js_1.getViteRoot)(operation);
|
|
32
34
|
(0, utils_js_1.assert)(root);
|
|
33
35
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(root, isDev, vikeVitePluginOptions);
|
|
36
|
+
const { isPrerenderingEnabled, isPrerenderingEnabledForAllPages } = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
37
|
+
prerenderContext ?? (prerenderContext = {
|
|
38
|
+
isPrerenderingEnabled,
|
|
39
|
+
isPrerenderingEnabledForAllPages,
|
|
40
|
+
output: null,
|
|
41
|
+
pageContexts: null
|
|
42
|
+
});
|
|
43
|
+
(0, utils_js_1.assert)(prerenderContext.isPrerenderingEnabled === isPrerenderingEnabled);
|
|
44
|
+
(0, utils_js_1.assert)(prerenderContext.isPrerenderingEnabledForAllPages === isPrerenderingEnabledForAllPages);
|
|
34
45
|
return {
|
|
35
46
|
_isDev: isDev,
|
|
36
47
|
_root: root,
|
|
@@ -38,11 +49,12 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
38
49
|
_vikeConfigObject: vikeConfig,
|
|
39
50
|
_vike: {
|
|
40
51
|
pages: vikeConfig.pages,
|
|
41
|
-
config: vikeConfig.global.config
|
|
52
|
+
config: vikeConfig.global.config,
|
|
53
|
+
prerenderContext
|
|
42
54
|
},
|
|
43
55
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
44
56
|
configVikePromise: Promise.resolve({
|
|
45
|
-
prerender:
|
|
57
|
+
prerender: isPrerenderingEnabled
|
|
46
58
|
})
|
|
47
59
|
};
|
|
48
60
|
}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.devConfig = devConfig;
|
|
7
7
|
exports.logDockerHint = logDockerHint;
|
|
8
|
+
const getResolvedConfig_js_1 = require("../../shared/getResolvedConfig.js");
|
|
8
9
|
const determineOptimizeDeps_js_1 = require("./determineOptimizeDeps.js");
|
|
9
10
|
const determineFsAllowList_js_1 = require("./determineFsAllowList.js");
|
|
10
11
|
const addSsrMiddleware_js_1 = require("../../shared/addSsrMiddleware.js");
|
|
@@ -17,7 +18,7 @@ if ((0, isErrorDebug_js_1.isErrorDebug)()) {
|
|
|
17
18
|
Error.stackTraceLimit = Infinity;
|
|
18
19
|
}
|
|
19
20
|
function devConfig() {
|
|
20
|
-
let
|
|
21
|
+
let vite5Config;
|
|
21
22
|
return [
|
|
22
23
|
{
|
|
23
24
|
name: 'vike:devConfig',
|
|
@@ -62,14 +63,14 @@ function devConfig() {
|
|
|
62
63
|
};
|
|
63
64
|
},
|
|
64
65
|
async configResolved(config_) {
|
|
65
|
-
|
|
66
|
-
await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(
|
|
67
|
-
await (0, determineFsAllowList_js_1.determineFsAllowList)(
|
|
66
|
+
vite5Config = config_;
|
|
67
|
+
await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(vite5Config);
|
|
68
|
+
await (0, determineFsAllowList_js_1.determineFsAllowList)(vite5Config);
|
|
68
69
|
if (!(0, isErrorDebug_js_1.isErrorDebug)()) {
|
|
69
70
|
await (0, getHttpRequestAsyncStore_js_1.installHttpRequestAsyncStore)();
|
|
70
|
-
(0, loggerVite_js_1.improveViteLogs)(
|
|
71
|
+
(0, loggerVite_js_1.improveViteLogs)(vite5Config);
|
|
71
72
|
}
|
|
72
|
-
logDockerHint(
|
|
73
|
+
logDockerHint(vite5Config.server.host);
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
76
|
{
|
|
@@ -80,6 +81,7 @@ function devConfig() {
|
|
|
80
81
|
configureServer: {
|
|
81
82
|
order: 'post',
|
|
82
83
|
handler(server) {
|
|
84
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(server?.config, vite5Config);
|
|
83
85
|
const hasHonoViteDevServer = !!config.plugins.find((p) => p.name === '@hono/vite-dev-server');
|
|
84
86
|
if (config.server.middlewareMode || hasHonoViteDevServer)
|
|
85
87
|
return;
|
|
@@ -1,12 +1,16 @@
|
|
|
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
|
exports.envVarsPlugin = envVarsPlugin;
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
4
8
|
const vite_1 = require("vite");
|
|
5
9
|
const utils_js_1 = require("../utils.js");
|
|
6
|
-
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
10
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
8
11
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
9
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
13
|
+
const getResolvedConfig_js_1 = require("../shared/getResolvedConfig.js");
|
|
10
14
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
11
15
|
// - Make import.meta.env work inside +config.js
|
|
12
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
|
|
@@ -18,17 +22,18 @@ const PUBLIC_ENV_WHITELIST = [
|
|
|
18
22
|
];
|
|
19
23
|
function envVarsPlugin() {
|
|
20
24
|
let envsAll;
|
|
21
|
-
let
|
|
25
|
+
let vite5Config;
|
|
22
26
|
return {
|
|
23
27
|
name: 'vike:envVars',
|
|
24
28
|
enforce: 'post',
|
|
25
29
|
configResolved(config_) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
envsAll = (0, vite_1.loadEnv)(
|
|
29
|
-
|
|
30
|
+
vite5Config = config_;
|
|
31
|
+
vite5Config.command;
|
|
32
|
+
envsAll = (0, vite_1.loadEnv)(vite5Config.mode, vite5Config.envDir || vite5Config.root, '');
|
|
33
|
+
vite5Config.plugins.sort((0, utils_js_1.lowerFirst)((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
30
34
|
},
|
|
31
35
|
transform(code, id, options) {
|
|
36
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
32
37
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
33
38
|
(0, utils_js_1.assertPosixPath)(id);
|
|
34
39
|
if (id.includes('/node_modules/'))
|
|
@@ -40,6 +45,7 @@ function envVarsPlugin() {
|
|
|
40
45
|
return;
|
|
41
46
|
const isBuild = config.command === 'build';
|
|
42
47
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
48
|
+
const s = new magic_string_1.default(code);
|
|
43
49
|
Object.entries(envsAll)
|
|
44
50
|
.filter(([key]) => {
|
|
45
51
|
// Already handled by Vite
|
|
@@ -48,12 +54,12 @@ function envVarsPlugin() {
|
|
|
48
54
|
})
|
|
49
55
|
.forEach(([envName, envVal]) => {
|
|
50
56
|
const envStatement = `import.meta.env.${envName}`;
|
|
51
|
-
const
|
|
57
|
+
const envStatementRegExStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
52
58
|
// Security check
|
|
53
59
|
{
|
|
54
60
|
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
|
|
55
61
|
if (isPrivate && isClientSide) {
|
|
56
|
-
if (!
|
|
62
|
+
if (!new RegExp(envStatementRegExStr).test(code))
|
|
57
63
|
return;
|
|
58
64
|
const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
|
|
59
65
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -72,16 +78,21 @@ function envVarsPlugin() {
|
|
|
72
78
|
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
73
79
|
}
|
|
74
80
|
// Apply
|
|
75
|
-
|
|
81
|
+
applyEnvVar(s, envStatementRegExStr, envVal);
|
|
76
82
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
if (!s.hasChanged())
|
|
84
|
+
return null;
|
|
85
|
+
return {
|
|
86
|
+
code: s.toString(),
|
|
87
|
+
map: s.generateMap({ hires: true, source: id })
|
|
88
|
+
};
|
|
82
89
|
}
|
|
83
90
|
};
|
|
84
91
|
}
|
|
85
|
-
function applyEnvVar(
|
|
86
|
-
|
|
92
|
+
function applyEnvVar(s, envStatementRegExStr, envVal) {
|
|
93
|
+
const envStatementRegEx = new RegExp(envStatementRegExStr, 'g');
|
|
94
|
+
let match;
|
|
95
|
+
while ((match = envStatementRegEx.exec(s.original))) {
|
|
96
|
+
s.overwrite(match.index, match.index + match[0].length, JSON.stringify(envVal));
|
|
97
|
+
}
|
|
87
98
|
}
|
|
@@ -7,6 +7,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.extractAssetsRE = void 0;
|
|
9
9
|
exports.extractAssetsPlugin = extractAssetsPlugin;
|
|
10
|
+
// Workaround to make client-side bundles include the CSS imports living in server-side-only code.
|
|
11
|
+
// - This is needed for HTML-only pages, and React Server Components.
|
|
12
|
+
// - We recommend using the debug flag to get an idea of how this plugin works: `$ DEBUG=vike:extractAssets pnpm exec vike build`. Then have a look at `dist/client/manifest.json` and see how `.page.server.js` entries have zero JavaScript but only CSS.
|
|
13
|
+
// - This appraoch supports import path aliases `vite.config.js#resolve.alias` https://vitejs.dev/config/#resolve-alias
|
|
14
|
+
const getResolvedConfig_js_1 = require("../shared/getResolvedConfig.js");
|
|
10
15
|
const utils_js_1 = require("../utils.js");
|
|
11
16
|
const virtual_files_js_1 = require("../../shared/virtual-files.js");
|
|
12
17
|
const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
@@ -26,7 +31,7 @@ const urlRE = /(\?|&)url(?:&|$)/;
|
|
|
26
31
|
const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
27
32
|
const debug = (0, utils_js_1.createDebugger)('vike:extractAssets');
|
|
28
33
|
function extractAssetsPlugin() {
|
|
29
|
-
let
|
|
34
|
+
let vite5Config;
|
|
30
35
|
let vikeConfig;
|
|
31
36
|
let isFixEnabled;
|
|
32
37
|
return [
|
|
@@ -37,6 +42,7 @@ function extractAssetsPlugin() {
|
|
|
37
42
|
apply: 'build',
|
|
38
43
|
enforce: 'post',
|
|
39
44
|
async transform(src, id, options) {
|
|
45
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
40
46
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
41
47
|
if (!extractAssetsRE.test(id)) {
|
|
42
48
|
return;
|
|
@@ -65,6 +71,7 @@ function extractAssetsPlugin() {
|
|
|
65
71
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
66
72
|
enforce: 'pre',
|
|
67
73
|
async resolveId(source, importer, options) {
|
|
74
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
68
75
|
if ((0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options)) {
|
|
69
76
|
// When building for the server, there should never be a `?extractAssets` query
|
|
70
77
|
(0, utils_js_1.assert)(!extractAssetsRE.test(source));
|
|
@@ -140,12 +147,12 @@ function extractAssetsPlugin() {
|
|
|
140
147
|
{
|
|
141
148
|
name: 'vike:extractAssets-4',
|
|
142
149
|
async configResolved(config_) {
|
|
143
|
-
|
|
144
|
-
vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(
|
|
145
|
-
isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(
|
|
150
|
+
vite5Config = config_;
|
|
151
|
+
vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(vite5Config);
|
|
152
|
+
isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(vite5Config);
|
|
146
153
|
if (!isFixEnabled) {
|
|
147
154
|
// https://github.com/vikejs/vike/issues/1060
|
|
148
|
-
(0, utils_js_1.assertUsage)(!
|
|
155
|
+
(0, utils_js_1.assertUsage)(!vite5Config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fileEnv = fileEnv;
|
|
7
|
+
const getResolvedConfig_js_1 = require("../shared/getResolvedConfig.js");
|
|
7
8
|
const utils_js_1 = require("../utils.js");
|
|
8
9
|
const extractAssetsPlugin_js_1 = require("./extractAssetsPlugin.js");
|
|
9
10
|
const extractExportNamesPlugin_js_1 = require("./extractExportNamesPlugin.js");
|
|
@@ -12,16 +13,20 @@ const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
|
12
13
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
13
14
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
14
15
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
16
|
+
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
15
17
|
function fileEnv() {
|
|
16
|
-
let
|
|
18
|
+
let vite5Config;
|
|
17
19
|
let viteDevServer;
|
|
18
20
|
return {
|
|
19
21
|
name: 'vike:fileEnv',
|
|
20
22
|
load(id, options) {
|
|
23
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
21
24
|
// In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
|
|
22
25
|
if (!viteDevServer)
|
|
23
26
|
return;
|
|
24
|
-
if (
|
|
27
|
+
if (!(0, getVikeConfig_js_1.isV1Design)(config))
|
|
28
|
+
return;
|
|
29
|
+
if (skip(config, id))
|
|
25
30
|
return;
|
|
26
31
|
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
27
32
|
if (id.endsWith('?direct'))
|
|
@@ -31,24 +36,25 @@ function fileEnv() {
|
|
|
31
36
|
const importers = Array.from(moduleInfo.importers)
|
|
32
37
|
.map((m) => m.id)
|
|
33
38
|
.filter((id) => id !== null);
|
|
34
|
-
assertFileEnv(id, !!options?.ssr, importers,
|
|
39
|
+
assertFileEnv(config, id, !!options?.ssr, importers,
|
|
35
40
|
// In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
|
|
36
41
|
true);
|
|
37
42
|
},
|
|
38
43
|
// In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
|
|
39
44
|
async transform(code, id, options) {
|
|
45
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
40
46
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
41
47
|
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
42
48
|
if (viteDevServer)
|
|
43
49
|
return;
|
|
44
|
-
if (skip(id))
|
|
50
|
+
if (skip(config, id))
|
|
45
51
|
return;
|
|
46
52
|
const isServerSide = !!options?.ssr;
|
|
47
53
|
if (!isWrongEnv(id, isServerSide))
|
|
48
54
|
return;
|
|
49
55
|
const { importers } = this.getModuleInfo(id);
|
|
50
56
|
// Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code splitted.
|
|
51
|
-
const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
|
|
57
|
+
const errMsg = getErrorMessage(config, id, isServerSide, importers, false, true);
|
|
52
58
|
// We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
|
|
53
59
|
const { exportNames } = await (0, parseEsModule_js_1.getExportNames)(code);
|
|
54
60
|
return (0, rollupSourceMap_js_1.sourceMapRemove)([
|
|
@@ -57,8 +63,9 @@ function fileEnv() {
|
|
|
57
63
|
].join('\n'));
|
|
58
64
|
},
|
|
59
65
|
generateBundle() {
|
|
66
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
60
67
|
Array.from(this.getModuleIds())
|
|
61
|
-
.filter((id) => !skip(id))
|
|
68
|
+
.filter((id) => !skip(config, id))
|
|
62
69
|
.forEach((moduleId) => {
|
|
63
70
|
const mod = this.getModuleInfo(moduleId);
|
|
64
71
|
const { importers } = mod;
|
|
@@ -69,20 +76,20 @@ function fileEnv() {
|
|
|
69
76
|
*/
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
72
|
-
assertFileEnv(moduleId, !!config.build.ssr, importers, false);
|
|
79
|
+
assertFileEnv(config, moduleId, !!config.build.ssr, importers, false);
|
|
73
80
|
});
|
|
74
81
|
},
|
|
75
82
|
configResolved(config_) {
|
|
76
|
-
|
|
83
|
+
vite5Config = config_;
|
|
77
84
|
},
|
|
78
85
|
configureServer(viteDevServer_) {
|
|
79
86
|
viteDevServer = viteDevServer_;
|
|
80
87
|
}
|
|
81
88
|
};
|
|
82
|
-
function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
|
|
89
|
+
function assertFileEnv(config, moduleId, isServerSide, importers, onlyWarn) {
|
|
83
90
|
if (!isWrongEnv(moduleId, isServerSide))
|
|
84
91
|
return;
|
|
85
|
-
const errMsg = getErrorMessage(moduleId, isServerSide, importers, onlyWarn, false);
|
|
92
|
+
const errMsg = getErrorMessage(config, moduleId, isServerSide, importers, onlyWarn, false);
|
|
86
93
|
if (onlyWarn) {
|
|
87
94
|
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
88
95
|
}
|
|
@@ -90,7 +97,7 @@ function fileEnv() {
|
|
|
90
97
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
|
-
function getErrorMessage(moduleId, isServerSide, importers, onlyWarn, noColor) {
|
|
100
|
+
function getErrorMessage(config, moduleId, isServerSide, importers, onlyWarn, noColor) {
|
|
94
101
|
const modulePath = getModulePath(moduleId);
|
|
95
102
|
const envActual = isServerSide ? 'server' : 'client';
|
|
96
103
|
const envExpect = isServerSide ? 'client' : 'server';
|
|
@@ -115,7 +122,7 @@ function fileEnv() {
|
|
|
115
122
|
const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
|
|
116
123
|
return modulePath.includes(suffixWrong);
|
|
117
124
|
}
|
|
118
|
-
function skip(id) {
|
|
125
|
+
function skip(config, id) {
|
|
119
126
|
// TODO/v1-release: remove
|
|
120
127
|
if (extractAssetsPlugin_js_1.extractAssetsRE.test(id) || extractExportNamesPlugin_js_1.extractExportNamesRE.test(id))
|
|
121
128
|
return true;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.importUserCode = importUserCode;
|
|
7
|
+
const getResolvedConfig_js_1 = require("../../shared/getResolvedConfig.js");
|
|
7
8
|
const vite_1 = require("vite");
|
|
8
9
|
const getVirtualFilePageConfigValuesAll_js_1 = require("./v1-design/virtual-files/getVirtualFilePageConfigValuesAll.js");
|
|
9
10
|
const getVirtualFileImportUserCode_js_1 = require("./getVirtualFileImportUserCode.js");
|
|
@@ -18,16 +19,16 @@ const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
|
18
19
|
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
19
20
|
const crawlPlusFiles_js_1 = require("./v1-design/getVikeConfig/crawlPlusFiles.js");
|
|
20
21
|
function importUserCode() {
|
|
21
|
-
let
|
|
22
|
+
let vite5Config;
|
|
22
23
|
let vikeConfig;
|
|
23
24
|
return {
|
|
24
25
|
name: 'vike:importUserCode',
|
|
25
26
|
async configResolved(config_) {
|
|
26
27
|
vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
|
|
27
|
-
|
|
28
|
+
vite5Config = config_;
|
|
28
29
|
// TODO/v1-release: remove
|
|
29
|
-
if (!(0, getVikeConfig_js_1.isV1Design)(
|
|
30
|
-
|
|
30
|
+
if (!(0, getVikeConfig_js_1.isV1Design)(vite5Config))
|
|
31
|
+
vite5Config.experimental.importGlobRestoreExtension = true;
|
|
31
32
|
},
|
|
32
33
|
resolveId(id) {
|
|
33
34
|
if ((0, virtual_files_js_1.isVirtualFileId)(id)) {
|
|
@@ -36,7 +37,7 @@ function importUserCode() {
|
|
|
36
37
|
},
|
|
37
38
|
async handleHotUpdate(ctx) {
|
|
38
39
|
try {
|
|
39
|
-
return await handleHotUpdate(ctx,
|
|
40
|
+
return await handleHotUpdate(ctx, vite5Config);
|
|
40
41
|
}
|
|
41
42
|
catch (err) {
|
|
42
43
|
// Vite swallows errors thrown by handleHotUpdate()
|
|
@@ -45,6 +46,7 @@ function importUserCode() {
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
async load(id, options) {
|
|
49
|
+
const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
|
|
48
50
|
if (!(0, virtual_files_js_1.isVirtualFileId)(id))
|
|
49
51
|
return undefined;
|
|
50
52
|
id = (0, virtual_files_js_1.getVirtualFileId)(id);
|
|
@@ -60,7 +62,7 @@ function importUserCode() {
|
|
|
60
62
|
}
|
|
61
63
|
},
|
|
62
64
|
configureServer(server) {
|
|
63
|
-
handleFileAddRemove(server,
|
|
65
|
+
handleFileAddRemove(server, vite5Config);
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
}
|
|
@@ -901,7 +901,7 @@ function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitio
|
|
|
901
901
|
if (configNamesKnownAll.includes(configName)) {
|
|
902
902
|
(0, utils_js_1.assertUsage)(false, `${sourceName} sets the value of the config ${configNameColored} which is a custom config that is defined with ${picocolors_1.default.underline('https://vike.dev/meta')} at a path that doesn't apply to ${locationId} — see ${picocolors_1.default.underline('https://vike.dev/config#inheritance')}`, { exitOnError });
|
|
903
903
|
}
|
|
904
|
-
const errMsg = `${sourceName} sets an unknown config ${
|
|
904
|
+
const errMsg = `${sourceName} sets an unknown Vike config, see ${picocolors_1.default.underline('https://vike.dev/cli')} for the list of CLI options.`;
|
|
905
905
|
// Missing vike-{react,vue,solid} installation
|
|
906
906
|
{
|
|
907
907
|
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
@@ -38,20 +38,24 @@ function previewConfig() {
|
|
|
38
38
|
config.appType = 'mpa'
|
|
39
39
|
*/
|
|
40
40
|
return () => {
|
|
41
|
-
|
|
41
|
+
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(config._vikeConfigObject);
|
|
42
|
+
const { isPrerenderingEnabledForAllPages, isPrerenderingEnabled } = prerenderConfigGlobal;
|
|
43
|
+
assertDist(isPrerenderingEnabledForAllPages);
|
|
42
44
|
// We cannot re-use Vite's static middleware: https://github.com/vitejs/vite/pull/14836#issuecomment-1788540300
|
|
43
45
|
addStaticAssetsMiddleware(server.middlewares);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, true, prerenderConfigGlobal.isPrerenderingEnabled);
|
|
46
|
+
if (!isPrerenderingEnabledForAllPages) {
|
|
47
|
+
(0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, true, isPrerenderingEnabled);
|
|
47
48
|
}
|
|
48
49
|
addStatic404Middleware(server.middlewares);
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
|
-
function assertDist() {
|
|
53
|
+
function assertDist(isPrerenderingEnabledForAllPages) {
|
|
53
54
|
const { outDirRoot, outDirClient, outDirServer } = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
54
|
-
[outDirRoot, outDirClient
|
|
55
|
+
const dirS = [outDirRoot, outDirClient];
|
|
56
|
+
if (!isPrerenderingEnabledForAllPages)
|
|
57
|
+
dirS.push(outDirServer);
|
|
58
|
+
dirS.forEach((outDirAny) => {
|
|
55
59
|
(0, utils_js_1.assertUsage)(fs_1.default.existsSync(outDirAny), `Cannot run ${picocolors_1.default.cyan('$ vike preview')}: your app isn't built (the build directory ${picocolors_1.default.cyan(outDirAny)} is missing). Make sure to run ${picocolors_1.default.cyan('$ vike build')} before running ${picocolors_1.default.cyan('$ vike preview')}.`);
|
|
56
60
|
});
|
|
57
61
|
}
|
|
@@ -12,6 +12,7 @@ function resolvePrerenderConfigGlobal(vikeConfig) {
|
|
|
12
12
|
const prerenderConfigGlobal = {
|
|
13
13
|
partial: pickFirst(prerenderSettings.map((c) => c.partial)) ?? false,
|
|
14
14
|
noExtraDir: pickFirst(prerenderSettings.map((c) => c.noExtraDir)) ?? false,
|
|
15
|
+
keepDistServer: pickFirst(prerenderSettings.map((c) => c.keepDistServer)) ?? false,
|
|
15
16
|
parallel: pickFirst(prerenderSettings.map((c) => c.parallel)) ?? true,
|
|
16
17
|
disableAutoRun: pickFirst(prerenderSettings.map((c) => c.disableAutoRun)) ?? false
|
|
17
18
|
};
|