繁体   English   中英

如何防止测试被汇总捆绑?

[英]How to prevent tests being bundled by rollup?

我正在构建一个反应组件 package 并希望将我的测试文件夹排除在我从汇总构建的 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中的测试,例如

"exclude": [
    "**/tests",
    "**/*.test.js",
  ]

如果您不关心类型检查您的测试文件,则接受的答案有效。 如果你这样做,而不是在tsconfig.json中排除它们,将排除作为 rollup.config.js 中的汇总rollup.config.js插件的参数。

plugins: [
  typescript({
    exclude: ["**/__tests__", "**/*.test.ts"]
  })
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM