【发布时间】:2021-09-01 03:32:47
【问题描述】:
项目的结构一般是这样的:
components
- my-component
- - my-component.ts
- - index.ts
其中 index.(ts/js) 总是包含
import MyComponent from './my-component';
export default MyComponent;
我想删除 index.(js/ts) 并仍然使用路径导入/需要我的组件
import MyComponent from './components/my-component' // not having the index file!
// Please, do not suggest importing them like this
import MyComponent from './components/my-component/my-component'
我使用 Webpack 5。我知道 Webpack 4 有一个 module,但它不适用于 5。
我希望 NodeJS/Webpack 查找自定义文件名而不是索引。
【问题讨论】:
-
索引文件在导入语句中被省略,如果你想用一个特定的名称导入它们,你可以重命名它们。这有什么用例?
-
我想要一个文件 components/my-component/my-component.ts,而不是 index.ts。然后我想导入那些我会导入 index.ts
标签: javascript node.js reactjs typescript webpack