Skip to content

Commit f555646

Browse files
committed
fix: make standalone builds easier (#1165, #1342)
1 parent d9acc70 commit f555646

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

vike/node/plugin/plugins/importBuild/index.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@ function getImporterCode(config: ResolvedConfig, pageFilesEntry: string) {
5050
return importerCode
5151
}
5252
function getImportPath(config: ResolvedConfig) {
53+
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
5354
const filePathAbsolute = toPosixPath(
5455
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
5556
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`)
5657
)
57-
const { outDirServer } = getOutDirs(config)
58-
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute)
59-
return filePathRelative
58+
if (
59+
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal/loadImportBuild' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
60+
true as boolean
61+
) {
62+
return 'vike/__internal/loadImportBuild'
63+
} else {
64+
const { outDirServer } = getOutDirs(config)
65+
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute)
66+
return filePathRelative
67+
}
6068
}

vike/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
"require": "./dist/cjs/node/runtime/page-files/setup.js",
106106
"node": "./dist/esm/node/runtime/page-files/setup.js",
107107
"types": "./dist/esm/node/runtime/page-files/setup.d.ts"
108+
},
109+
"./__internal/loadImportBuild": {
110+
"require": "./dist/cjs/node/runtime/globalContext/loadImportBuild.js",
111+
"node": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
112+
"types": "./dist/esm/node/runtime/globalContext/loadImportBuild.d.ts"
108113
}
109114
},
110115
"peerDependencies": {

0 commit comments

Comments
 (0)