【问题标题】:Separating TypeScript and JavaScript files分离 TypeScript 和 JavaScript 文件
【发布时间】:2017-11-14 11:15:35
【问题描述】:

我从英雄之旅教程https://angular.io/docs/ts/latest/guide/setup.html克隆了项目。

我想将 .js 文件分离到另一个目录,因为现在我将 .ts、.js 和 .js.map 文件放在一个目录中。

我尝试按照来自Separate Angular2 TypeScript files and JavaScript files into different folders, maybe 'dist‘ 的答案解决它,但在 systemjs.config.js 和 tsconfig.json 发生更改后,我得到一个错误:

Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:18 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/app/app.module
    Error: XHR error (404 Not Found) loading http://localhost:3000/app/app.module
        at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:1056:39)
        at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:424:31)
        at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:191:47)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:486:38)
    Error loading http://localhost:3000/app/app.module as "./app/app.module" from http://localhost:3000/main.js
        at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:1056:39)
        at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:424:31)
        at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:191:47)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:486:38)
    Error loading http://localhost:3000/app/app.module as "./app/app.module" from http://localhost:3000/main.js

【问题讨论】:

  • 你用什么IDE?
  • 视觉工作室代码
  • 如果大多数编辑检测到使用了打字稿,他们会将.js.js.map '折叠'并隐藏起来。现在它不像你描述的那样经常在不同的目录中。

标签: javascript angular typescript


【解决方案1】:

添加

   "files.exclude": {
    "**/*.js.map": true,
    "**/*.js": {
        "when": "$(basename).ts"
    }
},

到您的用户设置

【讨论】:

  • 我有问题。我的主目录是应用程序。当我在这个目录中有所有 .ts 文件时,我看不到 .js 和 .js.map 文件。但是当我创建一个目录 app/subdir/subdirectory 并将 .ts 文件放在那里时,我会在目录 app 中获得 .js 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-19
  • 2021-09-25
  • 2017-06-29
  • 2018-06-10
  • 2019-03-28
  • 1970-01-01
  • 2020-01-10
相关资源
最近更新 更多