[英]Shorter relative paths with Angular - Webpack and Typescript
So i see myself ending up with a lot of ../../../
in my imports. 因此,我发现自己在导入文件../../../
最终出现了很多../../../
How can i set a constant in a config so that both webpack and typescript resolve correctly? 如何在配置中设置常量,以便Webpack和Typescript都能正确解析?
I have tried doing the below, but it's unable to resolve the path in the import. 我已尝试执行以下操作,但无法解析导入中的路径。
tsconfig.json: tsconfig.json:
"baseUrl": ".",
"paths": {}
webpack.common.js
under module.exports
webpack.common.js
在module.exports
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, "src"), "node_modules"]
},
I intended to let typescript look from the main dir (above src), and ask webpack to get modules from "src". 我打算让Typescript从主目录中查找(在src之上),并要求webpack从“ src”中获取模块。
My IDE isn't complaining (So Typescript should be ok). 我的IDE没抱怨(所以Typescript应该没问题)。 Webpack is. Webpack是。
I almost got it right. 我几乎是正确的。 The webpack exports should be: Webpack导出应为:
resolve: {
extensions: ['.ts', '.js'],
modules: ["src", "node_modules"]
},
instead of 代替
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, "src"), "node_modules"]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.