简体   繁体   English

在Angular4 Webpack Starter中,tsconfig.webpack.json是否适用于webpack,而tsconfig.json是否适用于其他所有功能?

[英]In the Angular4 Webpack Starter, does tsconfig.webpack.json work for webpack while tsconfig.json works for everything else?

Please refer to this git repository: https://github.com/AngularClass/angular-starter 请参考这个git仓库: https : //github.com/AngularClass/angular-starter

The Angular4 Webpack Starter comes with 2 files: Angular4 Webpack Starter附带2个文件:

tsconfig.json

and

tsconfig.webpack.json

Each file has slightly different configurations for TypeScript. 每个文件的TypeScript配置略有不同。

My question is regarding how these 2 files work in relation to the project. 我的问题是关于这两个文件如何与项目相关的。

Will the tsconfig.webpack.json only be applied to the ts-loader used by Webpack? tsconfig.webpack.json仅应用于tsconfig.webpack.json使用的ts-loader? while the tsconfig.json file will apply to everything else? tsconfig.json文件将适用于其他所有内容吗?

Any information on what tsconfig.webpack.json would be greatly appreciated. 任何关于tsconfig.webpack.json的信息将不胜感激。

The short answer is yes. 简短的答案是肯定的。 The TypeScript loader registered with Webpack is explicitly configured to use the tsconfig.webpack.json file. 已向Webpack注册的TypeScript加载程序已显式配置为使用tsconfig.webpack.json文件。 This can be observed on line 133 of the common configuration . 这可以在常见配置的第133行看到 The tsconfig.json file is there for IDE support. tsconfig.json文件可用于IDE支持。

It is worth noting that, while you state that the template uses ts-loader , it actually uses awesome-typescript-loader . 值得注意的是,虽然您声明模板使用ts-loader ,但实际上使用awesome-typescript-loader

Having said that, both loaders will by default try to pick up a file named tsconfig.json and that the template is explicitly overriding this behavior on the linked line. 话虽如此,两个加载器默认都会尝试拾取一个名为tsconfig.json的文件,并且该模板正在链接行上显式覆盖此行为。

While there are multiple reasons why one might want to use more than one TypeScript script configuration file in a project, editors, such as Visual Studio Code, use the one named tsconfig.json to power features such as intellisense, set various options, and to determine the extent of a project. 尽管有多个原因可能导致一个项目中要使用多个TypeScript脚本配置文件的原因,但诸如Visual Studio Code之类的编辑器却使用了一个名为tsconfig.json功能来增强智能感知功能,设置各种选项以及确定一个项目的范围。

It is more than reasonable to use the same file for both and that is actually what would happen by default. 两者都使用相同的文件是绝对合理的,这实际上是默认情况下会发生的情况。

Remarks 备注

Please note that the AngularClass template is extremely bloated and complicated. 请注意, AngularClass模板非常肿且复杂。 Considering it is meant as a starting point, which you will no doubt add to, the amount of unnecessary boilerplate and cruft that you start out with by basing your application on such a template should be taken into very serious consideration. 考虑到这是一个起点,毫无疑问,您将以这样的模板为基础,将您的应用程序作为基础, 开始时不必要的样板和残料的数量会被添加到一个认真的考虑中。 This goes double if you are new to any of the tools, transpilers, or frameworks involved. 如果您不熟悉所涉及的任何工具,编译器或框架,那么它将翻倍。

By the way, I'm actually a contributor to that repository. 顺便说一下,我实际上是该存储库的贡献者。 They took a pull request from me that changed a utility function which someone filed an issue for as being confusing. 他们从我这里请求请求 ,更改了实用程序功能,有人提出了一个令人困惑的问题。 The funny thing was that I had removed that very function from our project long before I submitted the PR improving it. 有趣的是,在我提交PR进行改进之前,我已经从项目中删除了该功能。

Having worked on a project which was derived from one of their templates, I wasted a lot of time ripping out Webpack config related code that was not needed but was getting in the way. 在处理了一个从他们的模板之一衍生而来的项目之后,我浪费了很多时间来剔除那些 Webpack config 相关的代码,这些代码不是必需的,但是会妨碍您的工作。 We ended up with only a ~hundred lines of Webpack config total. 我们最终只获得了数百行Webpack配置。 I wasn't, and still am not a huge Webpack fan (JSPM for the win), but Webpack was not being utilized well by the template. 我不是,并且仍然不是Webpack的忠实拥护者(赢取JSPM),但是模板没有很好地利用Webpack。 Lots of unnecessary work was being done which actually made Webpack seem more complicated than it is. 许多不必要的工作正在做,这实际上使Webpack看起来比实际要复杂。 That entire helpers file is basically worthless and none of it had anything to do with Webback, or TypeScript, or even Angular. 整个助手文件基本上一文不值,与Webback,TypeScript甚至Angular无关。

This is also a bit troubling since the angular class website sells training material. 由于角度课程网站出售培训材料,因此这也令人不安。 There's nothing wrong with that in principle or in practice, but they create a lot of complexity in addition to what is inherent in an already complex tool chain. 原则上或实践上都没有错,但是除了已经很复杂的工具链固有的功能外,它们还带来了很多复杂性。

Will the tsconfig.webpack.json only be applied to the ts-loader used by Webpack? tsconfig.webpack.json是否仅应用于Webpack使用的ts-loader?

Yes, that is correct. 对,那是正确的。 Here is where the tsconfig.webpack.json is used in webpack.common.js : 这是 tsconfig.webpack.json中使用webpack.common.js

  new ngcWebpack.NgcWebpackPlugin({
    ...
    disabled: !AOT,
    tsConfig: helpers.root('tsconfig.webpack.json'),   <----------------
  }),

and for awesome-typescript-loader here : 对于这里的 awesome-typescript-loader

{
  loader: 'awesome-typescript-loader',
  options: {
    configFileName: 'tsconfig.webpack.json',  <-------------------
    useCache: !isProd
  }
},

while the tsconfig.json file will apply to everything else? 而tsconfig.json文件将适用于其他所有内容吗?

Yes, it's used for tslinting or if you need to produce declaration files. 是的,它用于tslinting或需要生成声明文件。 If you're working in IDE it can also be used for intellisense and other IDE specific functionality. 如果您在IDE中工作,它也可以用于智能感知和其他特定于IDE的功能。

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

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