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.
- package/dist/cjs/node/runtime/globalContext.js +1 -0
- package/dist/cjs/node/vite/onLoad.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
- package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
- package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +63 -57
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +101 -91
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +24 -16
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +67 -57
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +26 -20
- package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +41 -33
- package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +50 -37
- package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertNodeVersion.js +3 -1
- package/dist/cjs/utils/assertVersion.js +26 -5
- package/dist/cjs/utils/joinEnglish.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -0
- package/dist/esm/node/runtime/globalContext.js +1 -0
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
- package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
- package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +63 -57
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +101 -91
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +24 -16
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +67 -57
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +26 -20
- package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +41 -33
- package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +51 -38
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertNodeVersion.js +3 -1
- package/dist/esm/utils/assertVersion.d.ts +4 -3
- package/dist/esm/utils/assertVersion.js +23 -5
- package/dist/esm/utils/joinEnglish.js +2 -1
- package/package.json +2 -2
|
@@ -7,35 +7,39 @@ function pluginBaseUrls() {
|
|
|
7
7
|
return {
|
|
8
8
|
name: 'vike:pluginBaseUrls',
|
|
9
9
|
enforce: 'post',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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() ?
|
|
@@ -12,88 +12,90 @@ function pluginDistFileNames() {
|
|
|
12
12
|
name: 'vike:build:pluginDistFileNames',
|
|
13
13
|
apply: 'build',
|
|
14
14
|
enforce: 'post',
|
|
15
|
-
configResolved
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
|
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
|
|
10
|
-
|
|
9
|
+
configResolved: {
|
|
10
|
+
handler(config_) {
|
|
11
|
+
config = config_;
|
|
12
|
+
},
|
|
11
13
|
},
|
|
12
|
-
generateBundle
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
14
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
onWarnOriginal
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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,
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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 (!
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
{
|