我正在构建一个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
中汇总类型脚本插件的参数。
plugins: [
/* for @rollup/plugin-typescript */
typescript({
exclude: ["**/__tests__", "**/*.test.ts"]
})
/* or for rollup-plugin-typescript2 */
typescript({
tsconfigOverride: {
exclude: ["**/__tests__", "**/*.test.ts"]
}
})
]
您可以排除tsconfig.json中的测试,例如
"exclude": [
"**/tests",
"**/*.test.js",
]