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
@@ -22,54 +22,58 @@ function pluginDev() {
22
22
  {
23
23
  name: 'vike:pluginDev',
24
24
  apply: utils_js_1.applyDev,
25
- config() {
26
- return {
27
- appType: 'custom',
28
- // TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
29
- optimizeDeps: {
30
- exclude: [
31
- // We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
32
- 'vike/client',
33
- 'vike/client/router',
34
- // It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
35
- // ```
36
- // Client runtime loaded twice https://vike.dev/client-runtime-duplicated
37
- // ```
38
- 'vike/routing',
39
- 'vike/getPageContext',
40
- // We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
41
- // ```
42
- // 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
43
- // 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
44
- // ```
45
- '@brillout/json-serializer/parse',
46
- '@brillout/json-serializer/stringify',
47
- '@brillout/picocolors',
48
- // We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
49
- // ```
50
- // Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
51
- // 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
52
- // 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
53
- // ```
54
- // The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
55
- // ```js
56
- // // ../../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
57
- // import { parse as parse2 } from "@brillout/json-serializer/parse";
58
- // ```
59
- 'react-streaming',
60
- ],
61
- },
62
- };
25
+ config: {
26
+ handler() {
27
+ return {
28
+ appType: 'custom',
29
+ // TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
30
+ optimizeDeps: {
31
+ exclude: [
32
+ // We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
33
+ 'vike/client',
34
+ 'vike/client/router',
35
+ // It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
36
+ // ```
37
+ // Client runtime loaded twice https://vike.dev/client-runtime-duplicated
38
+ // ```
39
+ 'vike/routing',
40
+ 'vike/getPageContext',
41
+ // We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
42
+ // ```
43
+ // 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
44
+ // 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
45
+ // ```
46
+ '@brillout/json-serializer/parse',
47
+ '@brillout/json-serializer/stringify',
48
+ '@brillout/picocolors',
49
+ // We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
50
+ // ```
51
+ // Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
52
+ // 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
53
+ // 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
54
+ // ```
55
+ // The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
56
+ // ```js
57
+ // // ../../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
58
+ // import { parse as parse2 } from "@brillout/json-serializer/parse";
59
+ // ```
60
+ 'react-streaming',
61
+ ],
62
+ },
63
+ };
64
+ },
63
65
  },
64
- async configResolved(config_) {
65
- config = config_;
66
- await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(config);
67
- await (0, determineFsAllowList_js_1.determineFsAllowList)(config);
68
- if (!(0, isErrorDebug_js_1.isErrorDebug)()) {
69
- await (0, getHttpRequestAsyncStore_js_1.installHttpRequestAsyncStore)();
70
- (0, loggerVite_js_1.improveViteLogs)(config);
71
- }
72
- logDockerHint(config.server.host);
66
+ configResolved: {
67
+ async handler(config_) {
68
+ config = config_;
69
+ await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(config);
70
+ await (0, determineFsAllowList_js_1.determineFsAllowList)(config);
71
+ if (!(0, isErrorDebug_js_1.isErrorDebug)()) {
72
+ await (0, getHttpRequestAsyncStore_js_1.installHttpRequestAsyncStore)();
73
+ (0, loggerVite_js_1.improveViteLogs)(config);
74
+ }
75
+ logDockerHint(config.server.host);
76
+ },
73
77
  },
74
78
  },
75
79
  {
@@ -22,66 +22,72 @@ function pluginEnvVars() {
22
22
  return {
23
23
  name: 'vike:pluginEnvVars',
24
24
  enforce: 'post',
25
- configResolved(config_) {
26
- config = config_;
27
- envsAll = (0, vite_1.loadEnv)(config.mode, config.envDir || config.root, '');
28
- config.plugins.sort((0, utils_js_1.lowerFirst)((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
25
+ configResolved: {
26
+ handler(config_) {
27
+ config = config_;
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
+ },
29
31
  },
30
- transform(code, id, options) {
31
- id = (0, normalizeId_js_1.normalizeId)(id);
32
- (0, utils_js_1.assertPosixPath)(id);
33
- if (id.includes('/node_modules/'))
34
- return;
35
- (0, utils_js_1.assertPosixPath)(config.root);
36
- if (!id.startsWith(config.root))
37
- return;
38
- if (!code.includes('({}).'))
39
- return;
40
- const isBuild = config.command === 'build';
41
- const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
42
- const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
43
- // Find & check
44
- const replacements = Object.entries(envsAll)
45
- .filter(([key]) => {
46
- // Already handled by Vite
47
- const envPrefix = !config.envPrefix ? [] : (0, utils_js_1.isArray)(config.envPrefix) ? config.envPrefix : [config.envPrefix];
48
- return !envPrefix.some((prefix) => key.startsWith(prefix));
49
- })
50
- .map(([envName, envVal]) => {
51
- const envStatement = `({}).${envName}`;
52
- const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
53
- // Security check
54
- {
55
- const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
56
- if (isPrivate && isClientSide) {
57
- if (!new RegExp(envStatementRegExpStr).test(code))
58
- return;
59
- const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
60
- const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
61
- const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
62
- const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
63
- if (isBuild) {
64
- (0, utils_js_1.assertUsage)(false, errMsg);
65
- }
66
- else {
67
- // - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
68
- // - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
69
- (0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
32
+ transform: {
33
+ handler(code, id, options) {
34
+ id = (0, normalizeId_js_1.normalizeId)(id);
35
+ (0, utils_js_1.assertPosixPath)(id);
36
+ if (id.includes('/node_modules/'))
37
+ return;
38
+ (0, utils_js_1.assertPosixPath)(config.root);
39
+ if (!id.startsWith(config.root))
40
+ return;
41
+ if (!code.includes('({}).'))
42
+ return;
43
+ const isBuild = config.command === 'build';
44
+ const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
45
+ const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
46
+ // Find & check
47
+ const replacements = Object.entries(envsAll)
48
+ .filter(([key]) => {
49
+ // Already handled by Vite
50
+ const envPrefix = !config.envPrefix ? [] : (0, utils_js_1.isArray)(config.envPrefix) ? config.envPrefix : [config.envPrefix];
51
+ return !envPrefix.some((prefix) => key.startsWith(prefix));
52
+ })
53
+ .map(([envName, envVal]) => {
54
+ const envStatement = `({}).${envName}`;
55
+ const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
56
+ // Security check
57
+ {
58
+ const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
59
+ if (isPrivate && isClientSide) {
60
+ if (!new RegExp(envStatementRegExpStr).test(code))
61
+ return;
62
+ const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
63
+ const errMsgAddendum = isBuild
64
+ ? ''
65
+ : ' (Vike will prevent your app from building for production)';
66
+ const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
67
+ const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
68
+ if (isBuild) {
69
+ (0, utils_js_1.assertUsage)(false, errMsg);
70
+ }
71
+ else {
72
+ // - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
73
+ // - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
74
+ (0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
75
+ }
70
76
  }
77
+ // Double check
78
+ (0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
71
79
  }
72
- // Double check
73
- (0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
74
- }
75
- return { regExpStr: envStatementRegExpStr, replacement: envVal };
76
- })
77
- .filter(utils_js_1.isNotNullish);
78
- // Apply
79
- replacements.forEach(({ regExpStr, replacement }) => {
80
- magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
81
- });
82
- if (!magicString.hasChanged())
83
- return null;
84
- return getMagicStringResult();
80
+ return { regExpStr: envStatementRegExpStr, replacement: envVal };
81
+ })
82
+ .filter(utils_js_1.isNotNullish);
83
+ // Apply
84
+ replacements.forEach(({ regExpStr, replacement }) => {
85
+ magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
86
+ });
87
+ if (!magicString.hasChanged())
88
+ return null;
89
+ return getMagicStringResult();
90
+ },
85
91
  },
86
92
  };
87
93
  }
@@ -35,24 +35,26 @@ function pluginExtractAssets() {
35
35
  // In dev, things just work. (Because Vite's module graph erroneously conflates the Vite server-side importees with the client-side importees.)
36
36
  apply: 'build',
37
37
  enforce: 'post',
38
- async transform(src, id, options) {
39
- id = (0, normalizeId_js_1.normalizeId)(id);
40
- if (!extractAssetsRE.test(id)) {
41
- return;
42
- }
43
- if (isFixEnabled) {
44
- // I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
45
- (0, assertV1Design_js_1.assertV1Design)(vikeConfig._pageConfigs, true);
46
- (0, utils_js_1.assert)(false);
47
- }
48
- const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
49
- (0, utils_js_1.assert)(includeAssetsImportedByServer);
50
- (0, utils_js_1.assert)(!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options));
51
- const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
52
- const moduleNames = getImportedModules(importStatements);
53
- const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
54
- debugTransformResult(id, code, importStatements);
55
- return (0, utils_js_1.rollupSourceMapRemove)(code);
38
+ transform: {
39
+ async handler(src, id, options) {
40
+ id = (0, normalizeId_js_1.normalizeId)(id);
41
+ if (!extractAssetsRE.test(id)) {
42
+ return;
43
+ }
44
+ if (isFixEnabled) {
45
+ // I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
46
+ (0, assertV1Design_js_1.assertV1Design)(vikeConfig._pageConfigs, true);
47
+ (0, utils_js_1.assert)(false);
48
+ }
49
+ const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
50
+ (0, utils_js_1.assert)(includeAssetsImportedByServer);
51
+ (0, utils_js_1.assert)(!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options));
52
+ const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
53
+ const moduleNames = getImportedModules(importStatements);
54
+ const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
55
+ debugTransformResult(id, code, importStatements);
56
+ return (0, utils_js_1.rollupSourceMapRemove)(code);
57
+ },
56
58
  },
57
59
  },
58
60
  // This plugin appends `?extractAssets` to module IDs
@@ -63,89 +65,97 @@ function pluginExtractAssets() {
63
65
  // - rollup's `alias` plugin; https://github.com/rollup/plugins/blob/5363f55aa1933b6c650832b08d6a54cb9ea64539/packages/alias/src/index.ts
64
66
  // - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
65
67
  enforce: 'pre',
66
- async resolveId(source, importer, options) {
67
- if ((0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options)) {
68
- // When building for the server, there should never be a `?extractAssets` query
69
- (0, utils_js_1.assert)(!extractAssetsRE.test(source));
70
- (0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
71
- return;
72
- }
73
- // If there is no `importer` then `module` is an entry.
74
- // We don't need to append `?extractAssets` to entries because they already have `?extractAssets` as Vike appends `?extractAssets` to entries by using `import.meta.glob('/**/*.page.server.js', { as: "extractAssets" })` (see `generateImportGlobs.ts`).
75
- if (!importer) {
76
- return;
77
- }
78
- // We only append `?extractAssets` if the parent module has `?extractAssets`
79
- if (!extractAssetsRE.test(importer)) {
80
- return;
81
- }
82
- const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
83
- (0, utils_js_1.assert)(includeAssetsImportedByServer);
84
- let resolution = null;
85
- try {
86
- resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
87
- }
88
- catch { }
89
- // Sometimes Rollup fails to resolve. If it fails to resolve, we assume the dependency to be an npm package and we skip it. (I guess Rollup should always be able to resolve local dependencies?)
90
- if (!resolution)
91
- return emptyModule(source, importer);
92
- const { id: file, external } = resolution;
93
- // Nothing is externalized when building for the client-side
94
- (0, utils_js_1.assert)(external === false);
95
- // We include:
96
- // - CSS(/LESS/SCSS/...) files
97
- // - Asset files (`.svg`, `.pdf`, ...)
98
- // - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
99
- if (utils_js_1.styleFileRE.test(file) || (0, isAsset_js_1.isAsset)(file) || urlRE.test(file)) {
100
- debugOperation('INCLUDED', file, importer);
101
- return resolution;
102
- }
103
- // We erase `source` if its file doesn't contain JavaScript
104
- if (!(0, utils_js_1.isScriptFile)(file)) {
105
- return emptyModule(file, importer);
106
- }
107
- // If the import path resolves to a file in `node_modules/`, we ignore that file:
108
- // - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
109
- // - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
110
- (0, utils_js_1.assertPosixPath)(file);
111
- if (file.includes('/node_modules/')) {
112
- return emptyModule(file, importer);
113
- }
114
- // When a library is symlinked, it lives outside `root`.
115
- (0, utils_js_1.assertPosixPath)(config.root);
116
- if (!file.startsWith(config.root)) {
117
- return emptyModule(file, importer);
118
- }
119
- return appendExtractAssetsQuery(file, importer);
68
+ resolveId: {
69
+ async handler(source, importer, options) {
70
+ if ((0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options)) {
71
+ // When building for the server, there should never be a `?extractAssets` query
72
+ (0, utils_js_1.assert)(!extractAssetsRE.test(source));
73
+ (0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
74
+ return;
75
+ }
76
+ // If there is no `importer` then `module` is an entry.
77
+ // We don't need to append `?extractAssets` to entries because they already have `?extractAssets` as Vike appends `?extractAssets` to entries by using `import.meta.glob('/**/*.page.server.js', { as: "extractAssets" })` (see `generateImportGlobs.ts`).
78
+ if (!importer) {
79
+ return;
80
+ }
81
+ // We only append `?extractAssets` if the parent module has `?extractAssets`
82
+ if (!extractAssetsRE.test(importer)) {
83
+ return;
84
+ }
85
+ const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
86
+ (0, utils_js_1.assert)(includeAssetsImportedByServer);
87
+ let resolution = null;
88
+ try {
89
+ resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
90
+ }
91
+ catch { }
92
+ // Sometimes Rollup fails to resolve. If it fails to resolve, we assume the dependency to be an npm package and we skip it. (I guess Rollup should always be able to resolve local dependencies?)
93
+ if (!resolution)
94
+ return emptyModule(source, importer);
95
+ const { id: file, external } = resolution;
96
+ // Nothing is externalized when building for the client-side
97
+ (0, utils_js_1.assert)(external === false);
98
+ // We include:
99
+ // - CSS(/LESS/SCSS/...) files
100
+ // - Asset files (`.svg`, `.pdf`, ...)
101
+ // - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
102
+ if (utils_js_1.styleFileRE.test(file) || (0, isAsset_js_1.isAsset)(file) || urlRE.test(file)) {
103
+ debugOperation('INCLUDED', file, importer);
104
+ return resolution;
105
+ }
106
+ // We erase `source` if its file doesn't contain JavaScript
107
+ if (!(0, utils_js_1.isScriptFile)(file)) {
108
+ return emptyModule(file, importer);
109
+ }
110
+ // If the import path resolves to a file in `node_modules/`, we ignore that file:
111
+ // - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
112
+ // - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
113
+ (0, utils_js_1.assertPosixPath)(file);
114
+ if (file.includes('/node_modules/')) {
115
+ return emptyModule(file, importer);
116
+ }
117
+ // When a library is symlinked, it lives outside `root`.
118
+ (0, utils_js_1.assertPosixPath)(config.root);
119
+ if (!file.startsWith(config.root)) {
120
+ return emptyModule(file, importer);
121
+ }
122
+ return appendExtractAssetsQuery(file, importer);
123
+ },
120
124
  },
121
125
  },
122
126
  {
123
127
  name: 'vike:pluginExtractAssets-3',
124
128
  apply: 'build',
125
- load(id) {
126
- if (!(0, utils_js_1.isVirtualFileId)(id))
127
- return undefined;
128
- id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
129
- if (id === EMPTY_MODULE_ID) {
130
- return '// Erased by vike:pluginExtractAssets';
131
- }
129
+ load: {
130
+ handler(id) {
131
+ if (!(0, utils_js_1.isVirtualFileId)(id))
132
+ return undefined;
133
+ id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
134
+ if (id === EMPTY_MODULE_ID) {
135
+ return '// Erased by vike:pluginExtractAssets';
136
+ }
137
+ },
132
138
  },
133
- config() {
134
- if (debug.isActivated) {
135
- return { logLevel: 'silent' };
136
- }
139
+ config: {
140
+ handler() {
141
+ if (debug.isActivated) {
142
+ return { logLevel: 'silent' };
143
+ }
144
+ },
137
145
  },
138
146
  },
139
147
  {
140
148
  name: 'vike:pluginExtractAssets-4',
141
- async configResolved(config_) {
142
- config = config_;
143
- vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
144
- isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)();
145
- if (!isFixEnabled) {
146
- // https://github.com/vikejs/vike/issues/1060
147
- (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');
148
- }
149
+ configResolved: {
150
+ async handler(config_) {
151
+ config = config_;
152
+ vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
153
+ isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)();
154
+ if (!isFixEnabled) {
155
+ // https://github.com/vikejs/vike/issues/1060
156
+ (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');
157
+ }
158
+ },
149
159
  },
150
160
  },
151
161
  ];
@@ -17,25 +17,33 @@ function pluginExtractExportNames() {
17
17
  return {
18
18
  name: 'vike:pluginExtractExportNames',
19
19
  enforce: 'post',
20
- async transform(src, id, options) {
21
- id = (0, normalizeId_js_1.normalizeId)(id);
22
- const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
23
- if (extractExportNamesRE.test(id)) {
24
- const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
25
- debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
26
- return code;
27
- }
20
+ transform: {
21
+ async handler(src, id, options) {
22
+ id = (0, normalizeId_js_1.normalizeId)(id);
23
+ const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
24
+ if (extractExportNamesRE.test(id)) {
25
+ const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
26
+ debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
27
+ return code;
28
+ }
29
+ },
28
30
  },
29
- configureServer() {
30
- isDev = true;
31
+ configureServer: {
32
+ handler() {
33
+ isDev = true;
34
+ },
31
35
  },
32
- configResolved(config_) {
33
- config = config_;
36
+ configResolved: {
37
+ handler(config_) {
38
+ config = config_;
39
+ },
34
40
  },
35
- config() {
36
- if (debug.isActivated) {
37
- return { logLevel: 'silent' };
38
- }
41
+ config: {
42
+ handler() {
43
+ if (debug.isActivated) {
44
+ return { logLevel: 'silent' };
45
+ }
46
+ },
39
47
  },
40
48
  };
41
49
  }