vike 0.4.227-commit-68a216b → 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.
@@ -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 config;
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
- config = config_;
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 &&
@@ -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 config;
17
+ let vite5Config;
16
18
  return {
17
19
  name: 'vike:build:pluginDistPackageJsonFile',
18
20
  apply: 'build',
19
21
  configResolved(config_) {
20
- config = config_;
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,25 +1,30 @@
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");
7
- const rollupSourceMap_js_1 = require("../../shared/rollupSourceMap.js");
8
12
  // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
9
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).
10
14
  const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
11
15
  function pluginModuleBanner() {
12
- let config;
16
+ let vite5Config;
13
17
  return {
14
18
  name: 'vike:pluginModuleBanner',
15
19
  enforce: 'post',
16
20
  apply: 'build',
17
21
  configResolved(config_) {
18
- config = config_;
22
+ vite5Config = config_;
19
23
  },
20
24
  generateBundle: {
21
25
  order: 'post',
22
26
  handler(_options, bundle) {
27
+ const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
23
28
  for (const module of Object.values(bundle)) {
24
29
  if (module.type === 'chunk') {
25
30
  if ((0, isViteServerBuild_js_1.isViteServerBuild)(config)) {
@@ -38,6 +43,7 @@ function pluginModuleBanner() {
38
43
  transform: {
39
44
  order: 'post',
40
45
  handler(code, id, options) {
46
+ const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
41
47
  if (!(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options))
42
48
  return;
43
49
  if (id.startsWith('\0'))
@@ -45,9 +51,13 @@ function pluginModuleBanner() {
45
51
  id = (0, virtual_files_js_1.removeVirtualIdTag)(id);
46
52
  if (id.startsWith(config.root))
47
53
  id = id.slice(config.root.length + 1);
54
+ const s = new magic_string_1.default(code);
48
55
  // No need to insert a new line; Rollup formats the code and will insert a new line.
49
- const codeNew = `${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); ${code}`;
50
- return (0, rollupSourceMap_js_1.sourceMapPassthrough)(codeNew);
56
+ s.prepend(`${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); `);
57
+ return {
58
+ code: s.toString(),
59
+ map: s.generateMap({ hires: true, source: id })
60
+ };
51
61
  }
52
62
  }
53
63
  };
@@ -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 config;
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
- config = config_;
66
- await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(config);
67
- await (0, determineFsAllowList_js_1.determineFsAllowList)(config);
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)(config);
71
+ (0, loggerVite_js_1.improveViteLogs)(vite5Config);
71
72
  }
72
- logDockerHint(config.server.host);
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 config;
25
+ let vite5Config;
22
26
  return {
23
27
  name: 'vike:envVars',
24
28
  enforce: 'post',
25
29
  configResolved(config_) {
26
- config = config_;
27
- config.command;
28
- envsAll = (0, vite_1.loadEnv)(config.mode, config.envDir || config.root, '');
29
- config.plugins.sort((0, utils_js_1.lowerFirst)((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
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 envStatementRegEx = new RegExp((0, utils_js_1.escapeRegex)(envStatement) + '\\b', 'g');
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 (!envStatementRegEx.test(code))
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
- code = applyEnvVar(envStatementRegEx, envVal, code);
81
+ applyEnvVar(s, envStatementRegExStr, envVal);
76
82
  });
77
- // Line numbers didn't change.
78
- // - We only break the column number of a couple of lines, wich is acceptable.
79
- // - Anyways, I'm not even sure Vite supports high-resolution column number source mapping.
80
- const ret = (0, rollupSourceMap_js_1.sourceMapPassthrough)(code);
81
- return ret;
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(envStatementRegEx, envVal, code) {
86
- return code.replace(envStatementRegEx, JSON.stringify(envVal));
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 config;
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
- config = config_;
144
- vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
145
- isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(config);
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)(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
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");
@@ -14,17 +15,18 @@ const parseEsModule_js_1 = require("../shared/parseEsModule.js");
14
15
  const normalizeId_js_1 = require("../shared/normalizeId.js");
15
16
  const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
16
17
  function fileEnv() {
17
- let config;
18
+ let vite5Config;
18
19
  let viteDevServer;
19
20
  return {
20
21
  name: 'vike:fileEnv',
21
22
  load(id, options) {
23
+ const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
22
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.
23
25
  if (!viteDevServer)
24
26
  return;
25
27
  if (!(0, getVikeConfig_js_1.isV1Design)(config))
26
28
  return;
27
- if (skip(id))
29
+ if (skip(config, id))
28
30
  return;
29
31
  // For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
30
32
  if (id.endsWith('?direct'))
@@ -34,24 +36,25 @@ function fileEnv() {
34
36
  const importers = Array.from(moduleInfo.importers)
35
37
  .map((m) => m.id)
36
38
  .filter((id) => id !== null);
37
- assertFileEnv(id, !!options?.ssr, importers,
39
+ assertFileEnv(config, id, !!options?.ssr, importers,
38
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).
39
41
  true);
40
42
  },
41
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.
42
44
  async transform(code, id, options) {
45
+ const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
43
46
  id = (0, normalizeId_js_1.normalizeId)(id);
44
47
  // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
45
48
  if (viteDevServer)
46
49
  return;
47
- if (skip(id))
50
+ if (skip(config, id))
48
51
  return;
49
52
  const isServerSide = !!options?.ssr;
50
53
  if (!isWrongEnv(id, isServerSide))
51
54
  return;
52
55
  const { importers } = this.getModuleInfo(id);
53
56
  // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code splitted.
54
- const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
57
+ const errMsg = getErrorMessage(config, id, isServerSide, importers, false, true);
55
58
  // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
56
59
  const { exportNames } = await (0, parseEsModule_js_1.getExportNames)(code);
57
60
  return (0, rollupSourceMap_js_1.sourceMapRemove)([
@@ -60,8 +63,9 @@ function fileEnv() {
60
63
  ].join('\n'));
61
64
  },
62
65
  generateBundle() {
66
+ const config = (0, getResolvedConfig_js_1.getResolvedConfig)(this.environment?.config, vite5Config);
63
67
  Array.from(this.getModuleIds())
64
- .filter((id) => !skip(id))
68
+ .filter((id) => !skip(config, id))
65
69
  .forEach((moduleId) => {
66
70
  const mod = this.getModuleInfo(moduleId);
67
71
  const { importers } = mod;
@@ -72,20 +76,20 @@ function fileEnv() {
72
76
  */
73
77
  return;
74
78
  }
75
- assertFileEnv(moduleId, !!config.build.ssr, importers, false);
79
+ assertFileEnv(config, moduleId, !!config.build.ssr, importers, false);
76
80
  });
77
81
  },
78
82
  configResolved(config_) {
79
- config = config_;
83
+ vite5Config = config_;
80
84
  },
81
85
  configureServer(viteDevServer_) {
82
86
  viteDevServer = viteDevServer_;
83
87
  }
84
88
  };
85
- function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
89
+ function assertFileEnv(config, moduleId, isServerSide, importers, onlyWarn) {
86
90
  if (!isWrongEnv(moduleId, isServerSide))
87
91
  return;
88
- const errMsg = getErrorMessage(moduleId, isServerSide, importers, onlyWarn, false);
92
+ const errMsg = getErrorMessage(config, moduleId, isServerSide, importers, onlyWarn, false);
89
93
  if (onlyWarn) {
90
94
  (0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
91
95
  }
@@ -93,7 +97,7 @@ function fileEnv() {
93
97
  (0, utils_js_1.assertUsage)(false, errMsg);
94
98
  }
95
99
  }
96
- function getErrorMessage(moduleId, isServerSide, importers, onlyWarn, noColor) {
100
+ function getErrorMessage(config, moduleId, isServerSide, importers, onlyWarn, noColor) {
97
101
  const modulePath = getModulePath(moduleId);
98
102
  const envActual = isServerSide ? 'server' : 'client';
99
103
  const envExpect = isServerSide ? 'client' : 'server';
@@ -118,7 +122,7 @@ function fileEnv() {
118
122
  const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
119
123
  return modulePath.includes(suffixWrong);
120
124
  }
121
- function skip(id) {
125
+ function skip(config, id) {
122
126
  // TODO/v1-release: remove
123
127
  if (extractAssetsPlugin_js_1.extractAssetsRE.test(id) || extractExportNamesPlugin_js_1.extractExportNamesRE.test(id))
124
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 config;
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
- config = config_;
28
+ vite5Config = config_;
28
29
  // TODO/v1-release: remove
29
- if (!(0, getVikeConfig_js_1.isV1Design)(config))
30
- config.experimental.importGlobRestoreExtension = true;
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, config);
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, config);
65
+ handleFileAddRemove(server, vite5Config);
64
66
  }
65
67
  };
66
68
  }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResolvedConfig = getResolvedConfig;
4
+ function getResolvedConfig(vite6Config, vite5Config) {
5
+ return vite6Config ?? vite5Config;
6
+ }
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.227-commit-68a216b';
5
+ exports.PROJECT_VERSION = '0.4.227-commit-c9cc081';
@@ -1,3 +1,4 @@
1
+ import { getResolvedConfig } from '../../shared/getResolvedConfig.js';
1
2
  export { pluginAutoFullBuild };
2
3
  export { isPrerenderForceExit };
3
4
  import { build } from 'vite';
@@ -15,7 +16,7 @@ import { isViteClientBuild, isViteServerBuild_onlySsrEnv } from '../../shared/is
15
16
  assertIsSingleModuleInstance('build/pluginAutoFullBuild.ts');
16
17
  let forceExit = false;
17
18
  function pluginAutoFullBuild() {
18
- let config;
19
+ let vite5Config;
19
20
  let vikeConfig;
20
21
  return [
21
22
  {
@@ -24,7 +25,7 @@ function pluginAutoFullBuild() {
24
25
  enforce: 'pre',
25
26
  async configResolved(config_) {
26
27
  vikeConfig = await getVikeConfig(config_);
27
- config = config_;
28
+ vite5Config = config_;
28
29
  abortViteBuildSsr(vikeConfig);
29
30
  },
30
31
  writeBundle: {
@@ -33,6 +34,7 @@ function pluginAutoFullBuild() {
33
34
  order: 'pre',
34
35
  */
35
36
  async handler(options, bundle) {
37
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
36
38
  await handleAssetsManifest(config, this.environment, options, bundle);
37
39
  await triggerFullBuild(config, vikeConfig, this.environment, bundle);
38
40
  }
@@ -46,6 +48,7 @@ function pluginAutoFullBuild() {
46
48
  sequential: true,
47
49
  order: 'post',
48
50
  handler() {
51
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
49
52
  onSetupBuild();
50
53
  handleAssetsManifest_assertUsageCssTarget(config);
51
54
  if (forceExit &&
@@ -7,18 +7,20 @@
7
7
  * Reproduction: https://github.com/brillout/vite-plugin-ssr-server-import-syntax
8
8
  */
9
9
  // TODO/refactor: prefix all other plugins with `plugin` as well?
10
+ import { getResolvedConfig } from '../../shared/getResolvedConfig.js';
10
11
  export { pluginDistPackageJsonFile };
11
12
  import { rollupIsEsm } from '../../shared/rollupIsEsm.js';
12
13
  import { isViteServerBuild } from '../../shared/isViteServerBuild.js';
13
14
  function pluginDistPackageJsonFile() {
14
- let config;
15
+ let vite5Config;
15
16
  return {
16
17
  name: 'vike:build:pluginDistPackageJsonFile',
17
18
  apply: 'build',
18
19
  configResolved(config_) {
19
- config = config_;
20
+ vite5Config = config_;
20
21
  },
21
22
  generateBundle(options, bundle) {
23
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
22
24
  if (!isViteServerBuild(config))
23
25
  return;
24
26
  const isEsm = rollupIsEsm(options);
@@ -1,23 +1,25 @@
1
+ import { getResolvedConfig } from '../../shared/getResolvedConfig.js';
1
2
  export { pluginModuleBanner };
3
+ import MagicString from 'magic-string';
2
4
  import { assert } from '../../utils.js';
3
5
  import { removeVirtualIdTag } from '../../../shared/virtual-files.js';
4
6
  import { isViteServerBuild, isViteServerBuild_safe } from '../../shared/isViteServerBuild.js';
5
- import { sourceMapPassthrough } from '../../shared/rollupSourceMap.js';
6
7
  // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
7
8
  // 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).
8
9
  const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
9
10
  function pluginModuleBanner() {
10
- let config;
11
+ let vite5Config;
11
12
  return {
12
13
  name: 'vike:pluginModuleBanner',
13
14
  enforce: 'post',
14
15
  apply: 'build',
15
16
  configResolved(config_) {
16
- config = config_;
17
+ vite5Config = config_;
17
18
  },
18
19
  generateBundle: {
19
20
  order: 'post',
20
21
  handler(_options, bundle) {
22
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
21
23
  for (const module of Object.values(bundle)) {
22
24
  if (module.type === 'chunk') {
23
25
  if (isViteServerBuild(config)) {
@@ -36,6 +38,7 @@ function pluginModuleBanner() {
36
38
  transform: {
37
39
  order: 'post',
38
40
  handler(code, id, options) {
41
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
39
42
  if (!isViteServerBuild_safe(config, options))
40
43
  return;
41
44
  if (id.startsWith('\0'))
@@ -43,9 +46,13 @@ function pluginModuleBanner() {
43
46
  id = removeVirtualIdTag(id);
44
47
  if (id.startsWith(config.root))
45
48
  id = id.slice(config.root.length + 1);
49
+ const s = new MagicString(code);
46
50
  // No need to insert a new line; Rollup formats the code and will insert a new line.
47
- const codeNew = `${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); ${code}`;
48
- return sourceMapPassthrough(codeNew);
51
+ s.prepend(`${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); `);
52
+ return {
53
+ code: s.toString(),
54
+ map: s.generateMap({ hires: true, source: id })
55
+ };
49
56
  }
50
57
  }
51
58
  };
@@ -1,3 +1,4 @@
1
+ import { getResolvedConfig } from '../../shared/getResolvedConfig.js';
1
2
  export { devConfig };
2
3
  export { logDockerHint };
3
4
  import { determineOptimizeDeps } from './determineOptimizeDeps.js';
@@ -12,7 +13,7 @@ if (isErrorDebug()) {
12
13
  Error.stackTraceLimit = Infinity;
13
14
  }
14
15
  function devConfig() {
15
- let config;
16
+ let vite5Config;
16
17
  return [
17
18
  {
18
19
  name: 'vike:devConfig',
@@ -57,14 +58,14 @@ function devConfig() {
57
58
  };
58
59
  },
59
60
  async configResolved(config_) {
60
- config = config_;
61
- await determineOptimizeDeps(config);
62
- await determineFsAllowList(config);
61
+ vite5Config = config_;
62
+ await determineOptimizeDeps(vite5Config);
63
+ await determineFsAllowList(vite5Config);
63
64
  if (!isErrorDebug()) {
64
65
  await installHttpRequestAsyncStore();
65
- improveViteLogs(config);
66
+ improveViteLogs(vite5Config);
66
67
  }
67
- logDockerHint(config.server.host);
68
+ logDockerHint(vite5Config.server.host);
68
69
  }
69
70
  },
70
71
  {
@@ -75,6 +76,7 @@ function devConfig() {
75
76
  configureServer: {
76
77
  order: 'post',
77
78
  handler(server) {
79
+ const config = getResolvedConfig(server?.config, vite5Config);
78
80
  const hasHonoViteDevServer = !!config.plugins.find((p) => p.name === '@hono/vite-dev-server');
79
81
  if (config.server.middlewareMode || hasHonoViteDevServer)
80
82
  return;
@@ -1,10 +1,11 @@
1
+ import MagicString from 'magic-string';
1
2
  export { envVarsPlugin };
2
3
  import { loadEnv } from 'vite';
3
4
  import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
4
- import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
5
5
  import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
6
6
  import { normalizeId } from '../shared/normalizeId.js';
7
7
  import { isViteServerBuild_safe } from '../shared/isViteServerBuild.js';
8
+ import { getResolvedConfig } from '../shared/getResolvedConfig.js';
8
9
  // TODO/enventually: (after we implemented vike.config.js)
9
10
  // - Make import.meta.env work inside +config.js
10
11
  // - 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
@@ -16,17 +17,18 @@ const PUBLIC_ENV_WHITELIST = [
16
17
  ];
17
18
  function envVarsPlugin() {
18
19
  let envsAll;
19
- let config;
20
+ let vite5Config;
20
21
  return {
21
22
  name: 'vike:envVars',
22
23
  enforce: 'post',
23
24
  configResolved(config_) {
24
- config = config_;
25
- config.command;
26
- envsAll = loadEnv(config.mode, config.envDir || config.root, '');
27
- config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
25
+ vite5Config = config_;
26
+ vite5Config.command;
27
+ envsAll = loadEnv(vite5Config.mode, vite5Config.envDir || vite5Config.root, '');
28
+ vite5Config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
28
29
  },
29
30
  transform(code, id, options) {
31
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
30
32
  id = normalizeId(id);
31
33
  assertPosixPath(id);
32
34
  if (id.includes('/node_modules/'))
@@ -38,6 +40,7 @@ function envVarsPlugin() {
38
40
  return;
39
41
  const isBuild = config.command === 'build';
40
42
  const isClientSide = !isViteServerBuild_safe(config, options);
43
+ const s = new MagicString(code);
41
44
  Object.entries(envsAll)
42
45
  .filter(([key]) => {
43
46
  // Already handled by Vite
@@ -46,12 +49,12 @@ function envVarsPlugin() {
46
49
  })
47
50
  .forEach(([envName, envVal]) => {
48
51
  const envStatement = `import.meta.env.${envName}`;
49
- const envStatementRegEx = new RegExp(escapeRegex(envStatement) + '\\b', 'g');
52
+ const envStatementRegExStr = escapeRegex(envStatement) + '\\b';
50
53
  // Security check
51
54
  {
52
55
  const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
53
56
  if (isPrivate && isClientSide) {
54
- if (!envStatementRegEx.test(code))
57
+ if (!new RegExp(envStatementRegExStr).test(code))
55
58
  return;
56
59
  const modulePath = getModuleFilePathAbsolute(id, config);
57
60
  const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
@@ -70,16 +73,21 @@ function envVarsPlugin() {
70
73
  assert(!(isPrivate && isClientSide) || !isBuild);
71
74
  }
72
75
  // Apply
73
- code = applyEnvVar(envStatementRegEx, envVal, code);
76
+ applyEnvVar(s, envStatementRegExStr, envVal);
74
77
  });
75
- // Line numbers didn't change.
76
- // - We only break the column number of a couple of lines, wich is acceptable.
77
- // - Anyways, I'm not even sure Vite supports high-resolution column number source mapping.
78
- const ret = sourceMapPassthrough(code);
79
- return ret;
78
+ if (!s.hasChanged())
79
+ return null;
80
+ return {
81
+ code: s.toString(),
82
+ map: s.generateMap({ hires: true, source: id })
83
+ };
80
84
  }
81
85
  };
82
86
  }
83
- function applyEnvVar(envStatementRegEx, envVal, code) {
84
- return code.replace(envStatementRegEx, JSON.stringify(envVal));
87
+ function applyEnvVar(s, envStatementRegExStr, envVal) {
88
+ const envStatementRegEx = new RegExp(envStatementRegExStr, 'g');
89
+ let match;
90
+ while ((match = envStatementRegEx.exec(s.original))) {
91
+ s.overwrite(match.index, match.index + match[0].length, JSON.stringify(envVal));
92
+ }
85
93
  }
@@ -4,6 +4,7 @@
4
4
  // - This is needed for HTML-only pages, and React Server Components.
5
5
  // - 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.
6
6
  // - This appraoch supports import path aliases `vite.config.js#resolve.alias` https://vitejs.dev/config/#resolve-alias
7
+ import { getResolvedConfig } from '../shared/getResolvedConfig.js';
7
8
  export { extractAssetsPlugin };
8
9
  export { extractAssetsRE };
9
10
  import { assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage } from '../utils.js';
@@ -24,7 +25,7 @@ const urlRE = /(\?|&)url(?:&|$)/;
24
25
  const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
25
26
  const debug = createDebugger('vike:extractAssets');
26
27
  function extractAssetsPlugin() {
27
- let config;
28
+ let vite5Config;
28
29
  let vikeConfig;
29
30
  let isFixEnabled;
30
31
  return [
@@ -35,6 +36,7 @@ function extractAssetsPlugin() {
35
36
  apply: 'build',
36
37
  enforce: 'post',
37
38
  async transform(src, id, options) {
39
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
38
40
  id = normalizeId(id);
39
41
  if (!extractAssetsRE.test(id)) {
40
42
  return;
@@ -63,6 +65,7 @@ function extractAssetsPlugin() {
63
65
  // - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
64
66
  enforce: 'pre',
65
67
  async resolveId(source, importer, options) {
68
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
66
69
  if (isViteServerBuild_safe(config, options)) {
67
70
  // When building for the server, there should never be a `?extractAssets` query
68
71
  assert(!extractAssetsRE.test(source));
@@ -138,12 +141,12 @@ function extractAssetsPlugin() {
138
141
  {
139
142
  name: 'vike:extractAssets-4',
140
143
  async configResolved(config_) {
141
- config = config_;
142
- vikeConfig = await getVikeConfig(config);
143
- isFixEnabled = handleAssetsManifest_isFixEnabled(config);
144
+ vite5Config = config_;
145
+ vikeConfig = await getVikeConfig(vite5Config);
146
+ isFixEnabled = handleAssetsManifest_isFixEnabled(vite5Config);
144
147
  if (!isFixEnabled) {
145
148
  // https://github.com/vikejs/vike/issues/1060
146
- 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');
149
+ 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');
147
150
  }
148
151
  }
149
152
  }
@@ -1,3 +1,4 @@
1
+ import { getResolvedConfig } from '../shared/getResolvedConfig.js';
1
2
  export { fileEnv };
2
3
  import { assert, assertUsage, assertWarning, capitalizeFirstLetter, joinEnglish } from '../utils.js';
3
4
  import { extractAssetsRE } from './extractAssetsPlugin.js';
@@ -9,17 +10,18 @@ import { getExportNames } from '../shared/parseEsModule.js';
9
10
  import { normalizeId } from '../shared/normalizeId.js';
10
11
  import { isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
11
12
  function fileEnv() {
12
- let config;
13
+ let vite5Config;
13
14
  let viteDevServer;
14
15
  return {
15
16
  name: 'vike:fileEnv',
16
17
  load(id, options) {
18
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
17
19
  // 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.
18
20
  if (!viteDevServer)
19
21
  return;
20
22
  if (!isV1Design(config))
21
23
  return;
22
- if (skip(id))
24
+ if (skip(config, id))
23
25
  return;
24
26
  // For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
25
27
  if (id.endsWith('?direct'))
@@ -29,24 +31,25 @@ function fileEnv() {
29
31
  const importers = Array.from(moduleInfo.importers)
30
32
  .map((m) => m.id)
31
33
  .filter((id) => id !== null);
32
- assertFileEnv(id, !!options?.ssr, importers,
34
+ assertFileEnv(config, id, !!options?.ssr, importers,
33
35
  // 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).
34
36
  true);
35
37
  },
36
38
  // 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.
37
39
  async transform(code, id, options) {
40
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
38
41
  id = normalizeId(id);
39
42
  // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
40
43
  if (viteDevServer)
41
44
  return;
42
- if (skip(id))
45
+ if (skip(config, id))
43
46
  return;
44
47
  const isServerSide = !!options?.ssr;
45
48
  if (!isWrongEnv(id, isServerSide))
46
49
  return;
47
50
  const { importers } = this.getModuleInfo(id);
48
51
  // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code splitted.
49
- const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
52
+ const errMsg = getErrorMessage(config, id, isServerSide, importers, false, true);
50
53
  // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
51
54
  const { exportNames } = await getExportNames(code);
52
55
  return sourceMapRemove([
@@ -55,8 +58,9 @@ function fileEnv() {
55
58
  ].join('\n'));
56
59
  },
57
60
  generateBundle() {
61
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
58
62
  Array.from(this.getModuleIds())
59
- .filter((id) => !skip(id))
63
+ .filter((id) => !skip(config, id))
60
64
  .forEach((moduleId) => {
61
65
  const mod = this.getModuleInfo(moduleId);
62
66
  const { importers } = mod;
@@ -67,20 +71,20 @@ function fileEnv() {
67
71
  */
68
72
  return;
69
73
  }
70
- assertFileEnv(moduleId, !!config.build.ssr, importers, false);
74
+ assertFileEnv(config, moduleId, !!config.build.ssr, importers, false);
71
75
  });
72
76
  },
73
77
  configResolved(config_) {
74
- config = config_;
78
+ vite5Config = config_;
75
79
  },
76
80
  configureServer(viteDevServer_) {
77
81
  viteDevServer = viteDevServer_;
78
82
  }
79
83
  };
80
- function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
84
+ function assertFileEnv(config, moduleId, isServerSide, importers, onlyWarn) {
81
85
  if (!isWrongEnv(moduleId, isServerSide))
82
86
  return;
83
- const errMsg = getErrorMessage(moduleId, isServerSide, importers, onlyWarn, false);
87
+ const errMsg = getErrorMessage(config, moduleId, isServerSide, importers, onlyWarn, false);
84
88
  if (onlyWarn) {
85
89
  assertWarning(false, errMsg, { onlyOnce: true });
86
90
  }
@@ -88,7 +92,7 @@ function fileEnv() {
88
92
  assertUsage(false, errMsg);
89
93
  }
90
94
  }
91
- function getErrorMessage(moduleId, isServerSide, importers, onlyWarn, noColor) {
95
+ function getErrorMessage(config, moduleId, isServerSide, importers, onlyWarn, noColor) {
92
96
  const modulePath = getModulePath(moduleId);
93
97
  const envActual = isServerSide ? 'server' : 'client';
94
98
  const envExpect = isServerSide ? 'client' : 'server';
@@ -113,7 +117,7 @@ function fileEnv() {
113
117
  const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
114
118
  return modulePath.includes(suffixWrong);
115
119
  }
116
- function skip(id) {
120
+ function skip(config, id) {
117
121
  // TODO/v1-release: remove
118
122
  if (extractAssetsRE.test(id) || extractExportNamesRE.test(id))
119
123
  return true;
@@ -1,3 +1,4 @@
1
+ import { getResolvedConfig } from '../../shared/getResolvedConfig.js';
1
2
  export { importUserCode };
2
3
  import { normalizePath } from 'vite';
3
4
  import { getVirtualFilePageConfigValuesAll } from './v1-design/virtual-files/getVirtualFilePageConfigValuesAll.js';
@@ -13,16 +14,16 @@ import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
13
14
  import { updateUserFiles } from '../../../runtime/globalContext.js';
14
15
  import { isPlusFile } from './v1-design/getVikeConfig/crawlPlusFiles.js';
15
16
  function importUserCode() {
16
- let config;
17
+ let vite5Config;
17
18
  let vikeConfig;
18
19
  return {
19
20
  name: 'vike:importUserCode',
20
21
  async configResolved(config_) {
21
22
  vikeConfig = await getVikeConfig(config_);
22
- config = config_;
23
+ vite5Config = config_;
23
24
  // TODO/v1-release: remove
24
- if (!isV1Design(config))
25
- config.experimental.importGlobRestoreExtension = true;
25
+ if (!isV1Design(vite5Config))
26
+ vite5Config.experimental.importGlobRestoreExtension = true;
26
27
  },
27
28
  resolveId(id) {
28
29
  if (isVirtualFileId(id)) {
@@ -31,7 +32,7 @@ function importUserCode() {
31
32
  },
32
33
  async handleHotUpdate(ctx) {
33
34
  try {
34
- return await handleHotUpdate(ctx, config);
35
+ return await handleHotUpdate(ctx, vite5Config);
35
36
  }
36
37
  catch (err) {
37
38
  // Vite swallows errors thrown by handleHotUpdate()
@@ -40,6 +41,7 @@ function importUserCode() {
40
41
  }
41
42
  },
42
43
  async load(id, options) {
44
+ const config = getResolvedConfig(this.environment?.config, vite5Config);
43
45
  if (!isVirtualFileId(id))
44
46
  return undefined;
45
47
  id = getVirtualFileId(id);
@@ -55,7 +57,7 @@ function importUserCode() {
55
57
  }
56
58
  },
57
59
  configureServer(server) {
58
- handleFileAddRemove(server, config);
60
+ handleFileAddRemove(server, vite5Config);
59
61
  }
60
62
  };
61
63
  }
@@ -0,0 +1,2 @@
1
+ import type { ResolvedConfig } from 'vite';
2
+ export declare function getResolvedConfig(vite6Config: ResolvedConfig | undefined, vite5Config: ResolvedConfig): ResolvedConfig;
@@ -0,0 +1,3 @@
1
+ export function getResolvedConfig(vite6Config, vite5Config) {
2
+ return vite6Config ?? vite5Config;
3
+ }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.227-commit-68a216b";
1
+ export declare const PROJECT_VERSION: "0.4.227-commit-c9cc081";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.227-commit-68a216b';
2
+ export const PROJECT_VERSION = '0.4.227-commit-c9cc081';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.227-commit-68a216b",
3
+ "version": "0.4.227-commit-c9cc081",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -129,6 +129,7 @@
129
129
  "es-module-lexer": "^1.0.0",
130
130
  "esbuild": "^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0",
131
131
  "json5": "^2.0.0",
132
+ "magic-string": "^0.30.17",
132
133
  "picomatch": "^4.0.2",
133
134
  "semver": "^7.0.0",
134
135
  "sirv": "^3.0.1",