Skip to content

Commit

Permalink
[fix] add svelte field when packaging
Browse files Browse the repository at this point in the history
Several heuristics in Kit/vite-plugin-svelte to tell Vite to mark Svelte packages rely on the "svelte" property. Vite/Rollup/Webpack plugin can all deal with it.

Fixes #1959
  • Loading branch information
Simon Holthausen committed Sep 15, 2021
1 parent 1b799ab commit 1208ed6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
21 changes: 21 additions & 0 deletions packages/kit/src/packaging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ export async function make_package(config, cwd = process.cwd()) {
}

pkg.exports = { ...generated, ...pkg.exports };

// Several heuristics in Kit/vite-plugin-svelte to tell Vite to mark Svelte packages
// rely on the "svelte" property. Vite/Rollup/Webpack plugin can all deal with it.
// See https://github.com/sveltejs/kit/issues/1959 for more info and related threads.
if (pkg.exports['.']) {
const svelte_export = typeof pkg.exports['.'] === 'string' ? pkg.exports['.'] : undefined;
if (svelte_export) {
pkg.svelte = svelte_export;
} else {
console.warn(
'The "." entry in "exports" is not a string. ' +
'If you set it by hand, please also set one of the options as a "svelte" entry point'
);
}
} else {
console.warn(
'The "." entry in "exports" is not a string. ' +
'If you set it by hand, please also set one of the options as a "svelte" entry point'
);
}

write(path.join(cwd, config.kit.package.dir, 'package.json'), JSON.stringify(pkg, null, ' '));

const whitelist = fs.readdirSync(cwd).filter((file) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"./Test.svelte": "./Test.svelte",
"./Test2.svelte": "./Test2.svelte",
".": "./index.js"
}
},
"svelte": "./index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"./internal": "./internal/index.js",
"./Test.svelte": "./Test.svelte",
".": "./index.js"
}
},
"svelte": "./index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"./Test2.svelte": "./Test2.svelte",
"./utils": "./utils.js",
".": "./index.js"
}
},
"svelte": "./index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"./Test2.svelte": "./Test2.svelte",
"./utils": "./utils.js",
".": "./index.js"
}
},
"svelte": "./index.js"
}

0 comments on commit 1208ed6

Please sign in to comment.