Skip to content

Commit

Permalink
fix: make standalone builds easier (#1165, #1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Dec 11, 2023
1 parent d9acc70 commit f555646
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions vike/node/plugin/plugins/importBuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ function getImporterCode(config: ResolvedConfig, pageFilesEntry: string) {
return importerCode
}
function getImportPath(config: ResolvedConfig) {
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
const filePathAbsolute = toPosixPath(
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`)
)
const { outDirServer } = getOutDirs(config)
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute)
return filePathRelative
if (
// 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)
true as boolean
) {
return 'vike/__internal/loadImportBuild'
} else {
const { outDirServer } = getOutDirs(config)
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute)
return filePathRelative
}
}
5 changes: 5 additions & 0 deletions vike/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
"require": "./dist/cjs/node/runtime/page-files/setup.js",
"node": "./dist/esm/node/runtime/page-files/setup.js",
"types": "./dist/esm/node/runtime/page-files/setup.d.ts"
},
"./__internal/loadImportBuild": {
"require": "./dist/cjs/node/runtime/globalContext/loadImportBuild.js",
"node": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
"types": "./dist/esm/node/runtime/globalContext/loadImportBuild.d.ts"
}
},
"peerDependencies": {
Expand Down

0 comments on commit f555646

Please sign in to comment.