我正在构建一个 react 组件包,并希望将我的测试文件夹排除在我从汇总构建的 dist 文件中。
运行 rollup -c
后我的文件结构如下所示
.
├── dist
│ ├── index.js
│ ├── tests
│ ├── index.test.js
├── src
│ ├── index.tsx
│ ├── tests
│ ├── index.test.tsx
我的汇总配置如下所示:import typescript from 'rollup-plugin-typescript2'
import pkg from './package.json'
export default {
input: 'src/index.tsx',
output: [
{
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
strict: false
}
],
plugins: [typescript()],
external: ['react', 'react-dom', 'prop-types']
}
如何将我的测试目录从捆绑到 dist
中排除运行汇总时的文件?
最佳答案
如果您不关心类型检查您的测试文件,则接受的答案有效。如果你这样做,而不是在 tsconfig.json
中排除它们,将该排除作为参数添加到 rollup.config.js
中的汇总 typescript 插件.
plugins: [
/* for @rollup/plugin-typescript */
typescript({
exclude: ["**/__tests__", "**/*.test.ts"]
})
/* or for rollup-plugin-typescript2 */
typescript({
tsconfigOverride: {
exclude: ["**/__tests__", "**/*.test.ts"]
}
})
]
关于javascript - 如何防止测试被汇总捆绑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65347157/