Str*_*ch0 27 javascript npm reactjs webpack rollupjs
我正在构建一个 React 组件包,并希望将我的测试文件夹排除在从汇总构建的 dist 文件中捆绑之外。
\n运行后我的文件结构如下所示rollup -c
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dist\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.js\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tests\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.test.js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.tsx\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tests\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.test.tsx\nRun Code Online (Sandbox Code Playgroud)\n我的汇总配置如下所示:
\nimport typescript from 'rollup-plugin-typescript2'\n\nimport pkg from './package.json'\n\nexport default {\n input: 'src/index.tsx',\n output: [\n {\n file: pkg.main,\n format: 'cjs',\n exports: 'named',\n sourcemap: true,\n strict: false\n }\n ],\n plugins: [typescript()],\n external: ['react', 'react-dom', 'prop-types']\n}\nRun Code Online (Sandbox Code Playgroud)\ndist在运行汇总时,如何排除我的测试目录被捆绑到文件中?
dra*_*mus 51
如果您关心测试文件的类型检查,请不要在 中排除它们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"]
}
})
]
Run Code Online (Sandbox Code Playgroud)
Por*_*k12 12
您可以排除tsconfig.json中的测试,例如
"exclude": [
"**/tests",
"**/*.test.js",
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17170 次 |
| 最近记录: |