使用vite捆绑库时排除文件和文件夹

问题描述 投票:0回答:0

我正在尝试使用 vite(通过 vite.config.ts)发布一个库。我的代码库有一本故事书和一个应用程序设置。但是,当我发布我的库时,我只想包含

lib
文件夹下的文件。我不想包括
stories/*
App.tsx
以及我为我的应用程序准备的任何其他文件夹。以下代码是我的
vite.config.ts
- 无论如何,
src/
下的所有文件都包含在 dist 包中

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",
        }),
      ],
    },
  },
});
config bundle vite lib
© www.soinside.com 2019 - 2024. All rights reserved.