I am trying to publish a library using vite (via vite.config.ts). My codebase has a storybook and an app setup. However, when I publish my library I only want to include the files under the lib
folder. I do not want to include the stories/*
, App.tsx
and whatever else other folders I have for my app. The following code is my vite.config.ts
- No matter what, all files under src/
get included in the dist bundle
export default defineConfig({
plugins: [
react({
jsxImportSource: "@emotion/react",
}),
],
optimizeDeps: {
exclude: [
"react",
"src/stories",
"App.d.ts",
"main.d.ts",
"stories/*",
],
},
build: {
manifest: true,
minify: true,
reportCompressedSize: true,
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/lib/index.ts"),
name: "my-awesome-lib",
// the proper extensions will be added
fileName: (format) => `my-awesome-lib.${format}.js`,
},
rollupOptions: {
input: ["src/lib/index.ts"],
// dependencies that should not be include in your lib
// also have tried it here but it does not work
external: [
"react",
"src/stories",
"App.d.ts",
"main.d.ts",
"stories/*",
],
output: {
globals: {
react: "React",
},
},
plugins: [
typescriptPaths({
preserveExtensions: true,
}),
typescript({
sourceMap: true,
declaration: true,
outDir: "dist",
}),
],
},
},
});