Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 为什么ts加载器不编译我的类型脚本?_Typescript_Webpack_Ts Loader - Fatal编程技术网

Typescript 为什么ts加载器不编译我的类型脚本?

Typescript 为什么ts加载器不编译我的类型脚本?,typescript,webpack,ts-loader,Typescript,Webpack,Ts Loader,我试图使用Webpack使用ts加载程序编译一些类型脚本,但它并没有像我预期的那样运行tsc。如果我对ts文件进行更改,webpack不会将其编译回js,如果我完全删除生成的js文件并重新运行webpack,也会发生同样的情况 Typescript设置得很好,因为我可以运行/node\u modules/Typescript/bin/tsc,它可以很好地生成js文件。我认为ts loader应该对我的tsconfig.json运行tsc,对吗?如果是这样的话,为什么它不按预期接收更改并生成我的j

我试图使用Webpack使用ts加载程序编译一些类型脚本,但它并没有像我预期的那样运行tsc。如果我对ts文件进行更改,webpack不会将其编译回js,如果我完全删除生成的js文件并重新运行webpack,也会发生同样的情况

Typescript设置得很好,因为我可以运行
/node\u modules/Typescript/bin/tsc
,它可以很好地生成js文件。我认为ts loader应该对我的tsconfig.json运行tsc,对吗?如果是这样的话,为什么它不按预期接收更改并生成我的js

正如您所看到的,我的入口点是
/Client/boot Client.ts
,甚至在运行Web包时也不会编译它

我正在运行的特定webpack命令是:

/node\u modules/webpack/bin/webpack.js——进度

这将提供以下输出

[0] building modulests-loader: Using typescript@2.2.2 and C:\git\coliver\couchtrace\Couchtrace.Web\tsconfig.json
[1] building modulests-loader: Using typescript@2.2.2 and C:\git\coliver\couchtrace\Couchtrace.Web\tsconfig.json
[1] Hash: 568887199c9c2bcbe47ec00669704990969dbee5
Version: webpack 2.3.2
Child
    Hash: 568887199c9c2bcbe47e
    Time: 20096ms
                 Asset    Size  Chunks                    Chunk Names
        main-client.js  554 kB       0  [emitted]  [big]  main-client
    main-client.js.map  859 kB       0  [emitted]         main-client
       [0] delegated ./node_modules/rxjs/Observable.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
       [5] delegated ./node_modules/rxjs/Subject.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
      [14] delegated ./node_modules/@angular/core/index.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
      [19] ./~/rxjs/AsyncSubject.js 1.6 kB {0} [built]
      [20] ./~/rxjs/ReplaySubject.js 2.99 kB {0} [built]
      [33] delegated ./node_modules/angular2-universal/browser/index.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
      [34] ./~/rxjs/add/operator/map.js 156 bytes {0} [built]
      [60] ./Client/src/app.module.ts 1.86 kB {0} [built]
      [61] delegated ./node_modules/angular2-universal-polyfills/browser.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
      [68] ./~/rxjs/Rx.js 9.61 kB {0} [built]
     [180] ./~/rxjs/add/operator/takeUntil.js 186 bytes {0} [built]
     [335] ./Client/boot-client.ts 951 bytes {0} [built]
     [344] delegated ./node_modules/rxjs/symbol/rxSubscriber.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
     [351] delegated ./node_modules/rxjs/util/ObjectUnsubscribedError.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
     [353] delegated ./node_modules/@angular/router/index.js from dll-reference vendor_c9f874e7c2f104739cd8 42 bytes {0} [not cacheable] [built]
        + 345 hidden modules
Child
    Hash: c00669704990969dbee5
    Time: 20085ms
             Asset    Size  Chunks                    Chunk Names
    main-server.js  552 kB       0  [emitted]  [big]  main-server
       [5] delegated ./node_modules/rxjs/Subject.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [14] delegated ./node_modules/@angular/core/bundles/core.umd.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [19] ./~/rxjs/AsyncSubject.js 1.6 kB {0} [built]
      [20] ./~/rxjs/ReplaySubject.js 2.99 kB {0} [built]
      [21] ./~/rxjs/util/ArgumentOutOfRangeError.js 974 bytes {0} [built]
      [32] delegated ./node_modules/angular2-universal/node/index.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [53] delegated ./node_modules/rxjs/add/operator/map.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [59] ./Client/src/app.module.ts 1.86 kB {0} [built]
      [60] delegated ./node_modules/zone.js/dist/zone-node.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [61] delegated ./node_modules/angular2-universal-polyfills/node.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [62] delegated ./node_modules/aspnet-prerendering/index.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
      [69] ./~/rxjs/Rx.js 9.61 kB {0} [built]
     [336] ./Client/boot-server.ts 1.37 kB {0} [built]
     [356] delegated ./node_modules/rxjs/symbol/rxSubscriber.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
     [360] delegated ./node_modules/@angular/router/bundles/router.umd.js from dll-reference ./vendor 42 bytes {0} [not cacheable] [built]
        + 346 hidden modules
版本
  • 网页:2.3.2
  • ts加载器:2.0.3
  • 打字稿:2.2.2
webpack.config.js
ts loader
不会将任何文件写入磁盘。它编译您的TypeScript文件并将生成的JavaScript传递给webpack,这在内存中发生。没有理由输出已编译的JavaScript,因为它包含在包中。该包包含您需要的所有内容

您可以看到,
/Client/boot Client.ts
是通过以下行编译的(它并不意味着写入磁盘):

[335] ./Client/boot-client.ts 951 bytes {0} [built]

啊,好吧,这很有道理。因此,是否建议跳过手动typescript编译,而让webpack通过ts加载器完成它的工作?我的src中应该只有ts文件,不应该也需要相应的js文件吗?是的,如果你使用的是webpack,你不需要担心有js文件。你是想使用webpack还是手动编译它们,这取决于你是否想捆绑应用程序(基本上与JS使用webpack的原因相同)。好的,我现在看到了webpack的好处。谢谢你的帮助。
{
  "compilerOptions": {
    "noImplicitAny": false,
    "moduleResolution": "node",
    "target": "es5",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipDefaultLibCheck": true,
    "lib": [ "es6", "dom" ],
    "types": [ "node" ]
  },
  "exclude": [ "bin", "node_modules" ]
}
[335] ./Client/boot-client.ts 951 bytes {0} [built]