【问题标题】:How can separate js files and ts files automatically in angular after npm start?npm启动后如何自动以角度分离js文件和ts文件?
【发布时间】:2016-05-17 02:50:12
【问题描述】:

我可以通过修改 tsconfig.json 或 package.json 得到这个结果吗?

我想要这个结构:

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

没有这个:

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

【问题讨论】:

标签: javascript angularjs node.js


【解决方案1】:

如果你想在angular2中分离出.js和.ts文件,你只需要遵循两个步骤:-

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

2) 在systemjs.config.js 中映射您的文件夹,即修改映射对象

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

 }

【讨论】:

    【解决方案2】:

    是的,您可以使用 tsconfig.json 中的 outDir 选项告诉 TypeScript 编译器将 .js 文件输出到不同的目录,我建议也设置 rootDir 以避免在未来:

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

    不要忘记调整index.html中的路径。

    【讨论】:

    • 它在 Angular 2 - rc7 版本中不起作用。请更新
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 2018-09-26
    • 2023-04-02
    • 2018-09-19
    • 2017-05-27
    • 1970-01-01
    相关资源
    最近更新 更多