javascript - 定义文件的打字稿输出文件错误
问题描述
我正在尝试使用 ts > js 文件和 ts 定义文件构建我的项目,并在编译时对 js 文件进行签名。
目前文件正在正确构建,但 .d.ts 文件被放入dist/src
文件夹中,然后使用正确的路径。我怎样才能让这些在他们的 js 父母旁边编译。例如,dist/components/Select/index.d.ts
而不是错误的方式:dist/src/components/Select/index.d.ts
包.json
"build": "rm -rf dist && npx tsc && NODE_ENV=production babel src/components --out-dir dist --extensions '.tsx' --presets @babel/preset-typescript --presets @babel/preset-env --ignore __tests__,__snapshots__,__mocks__,stories.js,**/*.test.tsx",
tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"rootDirs": [
"src",
"stories",
"config"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "react-jsx",
// Ensure that .d.ts files are created by tsc, but not .js files
"declaration": true,
"emitDeclarationOnly": true,
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true,
"outDir": "./dist"
},
"include": ["./src/**/*"],
"exclude": [
"node_modules",
"dist",
"docs"
]
}
构建文件
dist
dist/FormGenerator
dist/Input
dist/Link
dist/List
dist/MoneyFormat
dist/Select
dist/Select/index.js
dist/Select/Select.js
dist/src
dist/src/components
dist/src/components/FormGenerator
dist/src/components/Input
dist/src/components/Link
dist/src/components/List
dist/src/components/MoneyFormat
dist/src/components/Select
dist/src/components/Select/index.d.ts
dist/src/components/Select/Select.d.ts
dist/src/components/Svg
dist/src/components/TemplateComponent
dist/src/components/Text
dist/src/components/index.d.ts
dist/src/themes
dist/src/setupTests.d.ts
dist/Svg
dist/TemplateComponent
dist/test-utils
dist/Text
dist/index.js
根目录结构
.github
.husky
.storybook
.vscode
dist
node_modules
reports
src
test-utils
.codacy.yml
.editorconfig
.env
.env.local
.eslintignore
.eslintrc
.gitignore
.npmrc
.prettierignore
.prettierrc
jest.config.js
package.json
README.md
setupFile.js
tsconfig.json
yarn.lock
解决方案
您在 src 目录之外有任何 .ts 文件吗?如果是这样,那么编译器也会编译该文件,并且最终的文件夹结构将包含 src。
推荐阅读
- sql - Oracle 11:加入两个选择
- asp.net-mvc-4 - Visual Studio - 在 MVC 4 中找不到匹配的视图
- typescript - 如何取消 Selenium 中的特定等待?
- python - 删除重复项(python)
- python-3.x - 使用 subprocess.run 将文件从一种类型转换为另一种类型
- vuex - 使用 vuex-persistedstate 和 js-cookie 保存 Vuex 状态
- ubuntu - 是否可以在 linux 终端中使用 say-command 行?(不说话)
- javascript - Stripe - 付款意图(3d 安全问题)
- excel - 运行时工作表粘贴错误:需要对象
- amazon-web-services - 像 AWS Elasticsearch 中的查询