Skip to content

Commit

Permalink
fix(build): ensure lib mode file name is correctly inferred for scope…
Browse files Browse the repository at this point in the history
…d packages (#1754)
  • Loading branch information
LinusBorg committed Jan 27, 2021
1 parent 470b4e4 commit c2e8806
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/playground/lib/package.json
@@ -1,5 +1,5 @@
{
"name": "my-lib",
"name": "@example/my-lib",
"private": true,
"version": "0.0.0",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions packages/vite/src/node/build.ts
Expand Up @@ -340,9 +340,7 @@ async function doBuild(

paralellBuilds.push(bundle)

const pkgName =
libOptions &&
JSON.parse(lookupFile(config.root, ['package.json']) || `{}`).name
const pkgName = libOptions && getPkgName(config.root)

const generate = (output: OutputOptions = {}) => {
return bundle[options.write ? 'write' : 'generate']({
Expand Down Expand Up @@ -432,6 +430,14 @@ async function doBuild(
}
}

function getPkgName(root: string) {
const { name } = JSON.parse(lookupFile(root, ['package.json']) || `{}`)

if (!name) throw new Error('no name found in package.json')

return name.startsWith('@') ? name.split('/')[1] : name
}

function createMoveToVendorChunkFn(config: ResolvedConfig): GetManualChunk {
const cache = new Map<string, boolean>()
return (id, { getModuleInfo }) => {
Expand Down

0 comments on commit c2e8806

Please sign in to comment.