简体   繁体   English

npm启动后,如何自动按角度分离js文件和ts文件?

[英]How can separate js files and ts files automatically in angular after npm start?

Can I get this result modifying tsconfig.json or package.json? 修改tsconfig.json或package.json可以得到此结果吗?

I want this structure: 我想要这样的结构:

angular2-quickstart
  app
    ts
      app.component.ts
      main.ts
    js
      app.component.js
      app.component.js.map
      main.js
      main.js.map
index.html
license.md

no this: 没有这个:

angular2-quickstart
  app
    app.component.ts
    main.ts
    app.component.js
    app.component.js.map
    main.js
    main.js.map
index.html
license.md

Yes, you can tell the TypeScript compiler to output .js files to a different directory using the outDir option in tsconfig.json , and I'd recommend setting the rootDir too so as to avoid unpleasant surprises in the future: 是的,你可以告诉编译器打字稿输出.js文件使用一个不同的目录outDir在选项tsconfig.json ,我建议你设置rootDir过,从而避免在未来不愉快的意外:

{
  "compilerOptions": {
    "outDir": "app/js",
    "rootDir": "app/ts",
  }
}

Don't forget to adjust paths in index.html . 不要忘记调整index.html路径。

If you want to separate out .js and .ts files in angular2, you have to follow only two steps:- 如果要在angular2中分离出.js和.ts文件,则只需执行以下两个步骤:

1) Add "outDir":"<folder name where you want to put your js Files>" within compilerOptions object in tsconfig.json file. 1)在tsconfig.json文件的compilerOptions对象中添加"outDir":"<folder name where you want to put your js Files>"

2) Map your folder in systemjs.config.js ie modify the map object like 2)在systemjs.config.js映射您的文件夹,即修改映射对象,例如

 map:{
     app:<Folder-Name which you have specified in outDir>
     ----
     ----

 }

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

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