vike 0.4.238-commit-d48a597 → 0.4.239-commit-050a4a3

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.
Files changed (60) hide show
  1. package/dist/cjs/node/runtime/globalContext.js +1 -0
  2. package/dist/cjs/node/vite/onLoad.js +1 -1
  3. package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
  4. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  5. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  6. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  7. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  8. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
  9. package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  10. package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  11. package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
  12. package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
  13. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +63 -57
  14. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +101 -91
  15. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +24 -16
  16. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +67 -57
  17. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +26 -20
  18. package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
  19. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +41 -33
  20. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  21. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
  22. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +50 -37
  23. package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  24. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
  25. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  26. package/dist/cjs/utils/assertNodeVersion.js +3 -1
  27. package/dist/cjs/utils/assertVersion.js +26 -5
  28. package/dist/cjs/utils/joinEnglish.js +2 -1
  29. package/dist/esm/node/runtime/globalContext.d.ts +2 -0
  30. package/dist/esm/node/runtime/globalContext.js +1 -0
  31. package/dist/esm/node/vite/onLoad.js +1 -1
  32. package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
  33. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  34. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  35. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  36. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  37. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
  38. package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  39. package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  40. package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
  41. package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
  42. package/dist/esm/node/vite/plugins/pluginEnvVars.js +63 -57
  43. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +101 -91
  44. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +24 -16
  45. package/dist/esm/node/vite/plugins/pluginFileEnv.js +67 -57
  46. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +26 -20
  47. package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
  48. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +41 -33
  49. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  50. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
  51. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +51 -38
  52. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  53. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
  54. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  55. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  56. package/dist/esm/utils/assertNodeVersion.js +3 -1
  57. package/dist/esm/utils/assertVersion.d.ts +4 -3
  58. package/dist/esm/utils/assertVersion.js +23 -5
  59. package/dist/esm/utils/joinEnglish.js +2 -1
  60. package/package.json +2 -2
@@ -7,35 +7,39 @@ function pluginBaseUrls() {
7
7
  return {
8
8
  name: 'vike:pluginBaseUrls',
9
9
  enforce: 'post',
10
- async config(config) {
11
- const isDev = config._isDev;
12
- assert(typeof isDev === 'boolean');
13
- const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
14
- const vikeConfig = await getVikeConfigInternal();
15
- basesResolved = resolveBase(baseViteOriginal, vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null);
16
- // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
17
- process.env.BASE_SERVER = basesResolved.baseServer;
18
- process.env.BASE_ASSETS = basesResolved.baseAssets;
19
- return {
20
- envPrefix: [
21
- 'VITE_', // Vite doesn't seem to merge in its default, see https://github.com/vikejs/vike/issues/554
22
- 'BASE_SERVER',
23
- 'BASE_ASSETS',
24
- ],
25
- base: basesResolved.baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
26
- _baseViteOriginal: baseViteOriginal,
27
- };
10
+ config: {
11
+ async handler(config) {
12
+ const isDev = config._isDev;
13
+ assert(typeof isDev === 'boolean');
14
+ const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
15
+ const vikeConfig = await getVikeConfigInternal();
16
+ basesResolved = resolveBase(baseViteOriginal, vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null);
17
+ // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
18
+ process.env.BASE_SERVER = basesResolved.baseServer;
19
+ process.env.BASE_ASSETS = basesResolved.baseAssets;
20
+ return {
21
+ envPrefix: [
22
+ 'VITE_', // Vite doesn't seem to merge in its default, see https://github.com/vikejs/vike/issues/554
23
+ 'BASE_SERVER',
24
+ 'BASE_ASSETS',
25
+ ],
26
+ base: basesResolved.baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
27
+ _baseViteOriginal: baseViteOriginal,
28
+ };
29
+ },
28
30
  },
29
- async configResolved(config) {
30
- const vikeConfig = await getVikeConfigInternal();
31
- const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null, config);
32
- assert(basesResolved2.baseServer === basesResolved.baseServer);
33
- assert(basesResolved2.baseAssets === basesResolved.baseAssets);
34
- /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
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/'`.)
36
- * - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
37
- assert(config.base === baseAssets)
38
- */
31
+ configResolved: {
32
+ async handler(config) {
33
+ const vikeConfig = await getVikeConfigInternal();
34
+ const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null, config);
35
+ assert(basesResolved2.baseServer === basesResolved.baseServer);
36
+ assert(basesResolved2.baseAssets === basesResolved.baseAssets);
37
+ /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
38
+ * - 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/'`.)
39
+ * - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
40
+ assert(config.base === baseAssets)
41
+ */
42
+ },
39
43
  },
40
44
  };
41
45
  }
@@ -46,35 +46,39 @@ function pluginBuildApp() {
46
46
  {
47
47
  name: 'vike:build:pluginBuildApp',
48
48
  apply: 'build',
49
- config(config) {
50
- return {
51
- environments: {
52
- ssr: {
53
- consumer: 'server',
54
- build: {
55
- outDir: resolveOutDir(config, true),
56
- ssr: true,
49
+ config: {
50
+ handler(config) {
51
+ return {
52
+ environments: {
53
+ ssr: {
54
+ consumer: 'server',
55
+ build: {
56
+ outDir: resolveOutDir(config, true),
57
+ ssr: true,
58
+ },
57
59
  },
58
- },
59
- client: {
60
- consumer: 'client',
61
- build: {
62
- outDir: resolveOutDir(config, false),
63
- copyPublicDir: true,
64
- ssr: false,
60
+ client: {
61
+ consumer: 'client',
62
+ build: {
63
+ outDir: resolveOutDir(config, false),
64
+ copyPublicDir: true,
65
+ ssr: false,
66
+ },
65
67
  },
66
68
  },
67
- },
68
- };
69
+ };
70
+ },
69
71
  },
70
72
  },
71
73
  {
72
74
  name: 'vike:build:pluginBuildApp:autoFullBuild:pre',
73
75
  apply: 'build',
74
76
  enforce: 'pre',
75
- async configResolved(config_) {
76
- config = config_;
77
- await abortViteBuildSsr();
77
+ configResolved: {
78
+ async handler(config_) {
79
+ config = config_;
80
+ await abortViteBuildSsr();
81
+ },
78
82
  },
79
83
  // TO-DO/eventually: stop using this writeBundle() hack and, instead, use the buildApp() implementation above.
80
84
  // - Could it cause issues if a tool uses the writeBundle() hack together with getVikeConfig() ?
@@ -40,8 +40,10 @@ function pluginBuildConfig() {
40
40
  return { build };
41
41
  },
42
42
  },
43
- buildStart() {
44
- onSetupBuild();
43
+ buildStart: {
44
+ handler() {
45
+ onSetupBuild();
46
+ },
45
47
  },
46
48
  },
47
49
  ];
@@ -12,88 +12,90 @@ function pluginDistFileNames() {
12
12
  name: 'vike:build:pluginDistFileNames',
13
13
  apply: 'build',
14
14
  enforce: 'post',
15
- configResolved(config) {
16
- const rollupOutputs = getRollupOutputs(config);
17
- // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
18
- rollupOutputs.forEach((rollupOutput) => {
19
- if (!('entryFileNames' in rollupOutput)) {
20
- rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
21
- }
22
- if (!('chunkFileNames' in rollupOutput)) {
23
- rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
24
- }
25
- if (!('assetFileNames' in rollupOutput)) {
26
- rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
27
- rollupOutput.assetFileNames.isTheOneSetByVike = true;
28
- assert(rollupOutput.assetFileNames.isTheOneSetByVike);
29
- }
30
- else {
31
- // If a user needs this:
32
- // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
33
- // - It's needed for getHash() of handleAssetsManifest()
34
- // - Asset URLs should always contain a hash: it's paramount for caching assets.
35
- // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
36
- assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
37
- }
38
- {
39
- const manualChunksOriginal = rollupOutput.manualChunks;
40
- rollupOutput.manualChunks = function (id, ...args) {
41
- if (manualChunksOriginal) {
42
- if (isCallable(manualChunksOriginal)) {
43
- const result = manualChunksOriginal.call(this, id, ...args);
44
- if (result !== undefined)
45
- return result;
46
- }
47
- else {
48
- assertUsage(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
49
- }
50
- }
51
- // Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
52
- // TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
53
- if (id.endsWith('.css')) {
54
- const userRootDir = config.root;
55
- if (id.startsWith(userRootDir)) {
56
- assertPosixPath(id);
57
- assertModuleId(id);
58
- let name;
59
- const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
60
- if (isNodeModules) {
61
- name = isNodeModules[1];
15
+ configResolved: {
16
+ handler(config) {
17
+ const rollupOutputs = getRollupOutputs(config);
18
+ // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
19
+ rollupOutputs.forEach((rollupOutput) => {
20
+ if (!('entryFileNames' in rollupOutput)) {
21
+ rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
22
+ }
23
+ if (!('chunkFileNames' in rollupOutput)) {
24
+ rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
25
+ }
26
+ if (!('assetFileNames' in rollupOutput)) {
27
+ rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
28
+ rollupOutput.assetFileNames.isTheOneSetByVike = true;
29
+ assert(rollupOutput.assetFileNames.isTheOneSetByVike);
30
+ }
31
+ else {
32
+ // If a user needs this:
33
+ // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
34
+ // - It's needed for getHash() of handleAssetsManifest()
35
+ // - Asset URLs should always contain a hash: it's paramount for caching assets.
36
+ // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
37
+ assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
38
+ }
39
+ {
40
+ const manualChunksOriginal = rollupOutput.manualChunks;
41
+ rollupOutput.manualChunks = function (id, ...args) {
42
+ if (manualChunksOriginal) {
43
+ if (isCallable(manualChunksOriginal)) {
44
+ const result = manualChunksOriginal.call(this, id, ...args);
45
+ if (result !== undefined)
46
+ return result;
62
47
  }
63
48
  else {
64
- const filePath = getModuleFilePathAbsolute(id, config);
65
- name = filePath;
66
- name = name.split('.').slice(0, -1).join('.'); // remove file extension
67
- name = name.split('/').filter(Boolean).join('_');
49
+ assertUsage(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
68
50
  }
69
- // Make fileHash the same between local development and CI
70
- const idStable = path.posix.relative(userRootDir, id);
71
- // Don't remove `?` queries because each `id` should belong to a unique bundle.
72
- const hash = getIdHash(idStable);
73
- return `${name}-${hash}`;
74
51
  }
75
- else {
76
- let name;
77
- const isVirtualModule = id.match(/virtual:([^:]+):/);
78
- if (isVirtualModule) {
79
- name = isVirtualModule[1];
80
- assert(name);
81
- }
82
- else if (
83
- // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
84
- id.startsWith('/__uno')) {
85
- name = 'uno';
52
+ // Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
53
+ // TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
54
+ if (id.endsWith('.css')) {
55
+ const userRootDir = config.root;
56
+ if (id.startsWith(userRootDir)) {
57
+ assertPosixPath(id);
58
+ assertModuleId(id);
59
+ let name;
60
+ const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
61
+ if (isNodeModules) {
62
+ name = isNodeModules[1];
63
+ }
64
+ else {
65
+ const filePath = getModuleFilePathAbsolute(id, config);
66
+ name = filePath;
67
+ name = name.split('.').slice(0, -1).join('.'); // remove file extension
68
+ name = name.split('/').filter(Boolean).join('_');
69
+ }
70
+ // Make fileHash the same between local development and CI
71
+ const idStable = path.posix.relative(userRootDir, id);
72
+ // Don't remove `?` queries because each `id` should belong to a unique bundle.
73
+ const hash = getIdHash(idStable);
74
+ return `${name}-${hash}`;
86
75
  }
87
76
  else {
88
- name = 'style';
77
+ let name;
78
+ const isVirtualModule = id.match(/virtual:([^:]+):/);
79
+ if (isVirtualModule) {
80
+ name = isVirtualModule[1];
81
+ assert(name);
82
+ }
83
+ else if (
84
+ // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
85
+ id.startsWith('/__uno')) {
86
+ name = 'uno';
87
+ }
88
+ else {
89
+ name = 'style';
90
+ }
91
+ const hash = getIdHash(id);
92
+ return `${name}-${hash}`;
89
93
  }
90
- const hash = getIdHash(id);
91
- return `${name}-${hash}`;
92
94
  }
93
- }
94
- };
95
- }
96
- });
95
+ };
96
+ }
97
+ });
98
+ },
97
99
  },
98
100
  };
99
101
  }
@@ -6,21 +6,25 @@ function pluginDistPackageJsonFile() {
6
6
  return {
7
7
  name: 'vike:build:pluginDistPackageJsonFile',
8
8
  apply: 'build',
9
- configResolved(config_) {
10
- config = config_;
9
+ configResolved: {
10
+ handler(config_) {
11
+ config = config_;
12
+ },
11
13
  },
12
- generateBundle(options, bundle) {
13
- if (!isViteServerSide(config, this.environment))
14
- return;
15
- const isEsm = rollupIsEsm(options);
16
- const fileName = 'package.json';
17
- if (bundle[fileName])
18
- return; // E.g. already generated by Telefunc / vike
19
- this.emitFile({
20
- fileName,
21
- type: 'asset',
22
- source: getPackageJsonContent(isEsm),
23
- });
14
+ generateBundle: {
15
+ handler(options, bundle) {
16
+ if (!isViteServerSide(config, this.environment))
17
+ return;
18
+ const isEsm = rollupIsEsm(options);
19
+ const fileName = 'package.json';
20
+ if (bundle[fileName])
21
+ return; // E.g. already generated by Telefunc / vike
22
+ this.emitFile({
23
+ fileName,
24
+ type: 'asset',
25
+ source: getPackageJsonContent(isEsm),
26
+ });
27
+ },
24
28
  },
25
29
  };
26
30
  }
@@ -10,8 +10,10 @@ function pluginModuleBanner() {
10
10
  name: 'vike:build:pluginModuleBanner',
11
11
  enforce: 'post',
12
12
  apply: 'build',
13
- configResolved(config_) {
14
- config = config_;
13
+ configResolved: {
14
+ handler(config_) {
15
+ config = config_;
16
+ },
15
17
  },
16
18
  transform: {
17
19
  order: 'post',
@@ -17,8 +17,10 @@ function pluginProdBuildEntry() {
17
17
  name: 'vike:build:pluginProdBuildEntry',
18
18
  apply: 'build',
19
19
  enforce: 'post',
20
- async configResolved(config_) {
21
- config = config_;
20
+ configResolved: {
21
+ async handler(config_) {
22
+ config = config_;
23
+ },
22
24
  },
23
25
  },
24
26
  ...serverProductionEntryPlugin({
@@ -5,24 +5,26 @@ function pluginSuppressRollupWarning() {
5
5
  name: 'vike:build:pluginSuppressRollupWarning',
6
6
  apply: 'build',
7
7
  enforce: 'post',
8
- async configResolved(config) {
9
- const onWarnOriginal = config.build.rollupOptions.onwarn;
10
- config.build.rollupOptions.onwarn = function (warning, warn) {
11
- // Suppress
12
- if (suppressUnusedImport(warning))
13
- return;
14
- if (suppressEmptyBundle(warning))
15
- return;
16
- if (suppressUseClientDirective(warning))
17
- return;
18
- // Pass through
19
- if (onWarnOriginal) {
20
- onWarnOriginal.apply(this, arguments);
21
- }
22
- else {
23
- warn(warning);
24
- }
25
- };
8
+ configResolved: {
9
+ async handler(config) {
10
+ const onWarnOriginal = config.build.rollupOptions.onwarn;
11
+ config.build.rollupOptions.onwarn = function (warning, warn) {
12
+ // Suppress
13
+ if (suppressUnusedImport(warning))
14
+ return;
15
+ if (suppressEmptyBundle(warning))
16
+ return;
17
+ if (suppressUseClientDirective(warning))
18
+ return;
19
+ // Pass through
20
+ if (onWarnOriginal) {
21
+ onWarnOriginal.apply(this, arguments);
22
+ }
23
+ else {
24
+ warn(warning);
25
+ }
26
+ };
27
+ },
26
28
  },
27
29
  };
28
30
  }
@@ -1,9 +1,8 @@
1
1
  export { pluginCommon };
2
- import { assert, assertUsage, assertWarning, findPackageJson, hasProp, isDevCheck, isDocker, isObject, isVitest, } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isObject, isVitest, } from '../utils.js';
3
3
  import { assertRollupInput } from './pluginBuild/pluginBuildConfig.js';
4
4
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
5
5
  import pc from '@brillout/picocolors';
6
- import path from 'node:path';
7
6
  import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
8
7
  import { isViteCliCall } from '../shared/isViteCliCall.js';
9
8
  import { isVikeCliOrApi } from '../../api/context.js';
@@ -42,10 +41,12 @@ function pluginCommon(vikeVitePluginOptions) {
42
41
  },
43
42
  {
44
43
  name: pluginName,
45
- configResolved(config) {
46
- assertViteRoot(config._rootResolvedEarly, config);
47
- assertSingleInstance(config);
48
- installRequireShim_setUserRootDir(config.root);
44
+ configResolved: {
45
+ handler(config) {
46
+ assertViteRoot(config._rootResolvedEarly, config);
47
+ assertSingleInstance(config);
48
+ installRequireShim_setUserRootDir(config.root);
49
+ },
49
50
  },
50
51
  },
51
52
  {
@@ -64,7 +65,6 @@ function pluginCommon(vikeVitePluginOptions) {
64
65
  workaroundCI(config);
65
66
  assertRollupInput(config);
66
67
  assertResolveAlias(config);
67
- assertEsm(config.root);
68
68
  assertVikeCliOrApi(config);
69
69
  temp_supportOldInterface(config);
70
70
  await emitServerEntryOnlyIfNeeded(config);
@@ -107,7 +107,7 @@ function setDefault(setting, value, configFromUser, configFromVike) {
107
107
  /*
108
108
  import { version } from 'vite'
109
109
  function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
110
- if (!isVersionOrAbove(version, '5.0.12')) return
110
+ if (!isVersionMatch(version, ['5.0.12'])) return
111
111
  // @ts-ignore Not released yet: https://github.com/vitejs/vite/pull/10939/files#diff-5a3d42620df2c6b17e25f440ffdb67683dee7ef57317674d19f41d5f30502310L5
112
112
  config.ssr.external ??= true
113
113
  }
@@ -120,20 +120,6 @@ function workaroundCI(config) {
120
120
  (_b = config.preview).host ?? (_b.host = true);
121
121
  }
122
122
  }
123
- function assertEsm(userViteRoot) {
124
- const found = findPackageJson(userViteRoot);
125
- if (!found)
126
- return;
127
- const { packageJson, packageJsonPath } = found;
128
- let dir = path.posix.dirname(packageJsonPath);
129
- if (dir !== '/') {
130
- assert(!dir.endsWith('/'));
131
- dir = dir + '/';
132
- }
133
- assert(dir.endsWith('/'));
134
- dir = pc.dim(dir);
135
- assertWarning(packageJson.type === 'module', `We recommend setting ${dir}package.json#type to "module", see https://vike.dev/CJS`, { onlyOnce: true });
136
- }
137
123
  function assertSingleInstance(config) {
138
124
  const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
139
125
  assertUsage(numberOfInstances === 1, `Vike's Vite plugin (${pc.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);
@@ -17,54 +17,58 @@ function pluginDev() {
17
17
  {
18
18
  name: 'vike:pluginDev',
19
19
  apply: applyDev,
20
- config() {
21
- return {
22
- appType: 'custom',
23
- // TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
24
- optimizeDeps: {
25
- exclude: [
26
- // We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
27
- 'vike/client',
28
- 'vike/client/router',
29
- // It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
30
- // ```
31
- // Client runtime loaded twice https://vike.dev/client-runtime-duplicated
32
- // ```
33
- 'vike/routing',
34
- 'vike/getPageContext',
35
- // We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
36
- // ```
37
- // 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
38
- // 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
39
- // ```
40
- '@brillout/json-serializer/parse',
41
- '@brillout/json-serializer/stringify',
42
- '@brillout/picocolors',
43
- // We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
44
- // ```
45
- // Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
46
- // 343| // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
47
- // 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
48
- // ```
49
- // The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
50
- // ```js
51
- // // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
52
- // import { parse as parse2 } from "@brillout/json-serializer/parse";
53
- // ```
54
- 'react-streaming',
55
- ],
56
- },
57
- };
20
+ config: {
21
+ handler() {
22
+ return {
23
+ appType: 'custom',
24
+ // TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
25
+ optimizeDeps: {
26
+ exclude: [
27
+ // We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
28
+ 'vike/client',
29
+ 'vike/client/router',
30
+ // It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
31
+ // ```
32
+ // Client runtime loaded twice https://vike.dev/client-runtime-duplicated
33
+ // ```
34
+ 'vike/routing',
35
+ 'vike/getPageContext',
36
+ // We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
37
+ // ```
38
+ // 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
39
+ // 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
40
+ // ```
41
+ '@brillout/json-serializer/parse',
42
+ '@brillout/json-serializer/stringify',
43
+ '@brillout/picocolors',
44
+ // We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
45
+ // ```
46
+ // Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
47
+ // 343| // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
48
+ // 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
49
+ // ```
50
+ // The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
51
+ // ```js
52
+ // // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
53
+ // import { parse as parse2 } from "@brillout/json-serializer/parse";
54
+ // ```
55
+ 'react-streaming',
56
+ ],
57
+ },
58
+ };
59
+ },
58
60
  },
59
- async configResolved(config_) {
60
- config = config_;
61
- await determineOptimizeDeps(config);
62
- await determineFsAllowList(config);
63
- if (!isErrorDebug()) {
64
- await installHttpRequestAsyncStore();
65
- improveViteLogs(config);
66
- }
67
- logDockerHint(config.server.host);
61
+ configResolved: {
62
+ async handler(config_) {
63
+ config = config_;
64
+ await determineOptimizeDeps(config);
65
+ await determineFsAllowList(config);
66
+ if (!isErrorDebug()) {
67
+ await installHttpRequestAsyncStore();
68
+ improveViteLogs(config);
69
+ }
70
+ logDockerHint(config.server.host);
71
+ },
68
72
  },
69
73
  },
70
74
  {