【问题标题】:How to run Angular 2 form IntelliJ using Tomcat?如何使用 Tomcat 从 IntelliJ 运行 Angular 2?
【发布时间】:2016-08-18 15:32:25
【问题描述】:

我正在一个由 Tomcat 托管的项目中编写 Angular 2 代码。我现在添加一些 Angular 2 代码。

我使用了使用实时监视编译器的quickstart 项目。这意味着它会在检测到更改时编译ts 文件。

但是,现在所有的项目都由 Tomcat 托管。那么,如何编译ts 文件呢?手动?

每次代码更改都按build project

我看到package.json 包括这个:

  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },

但是当我跑步时

➜  angular2 git:(push_n) ✗ npm tsc:w

Usage: npm <command>

where <command> is one of:
    access, adduser, bin, bugs, c, cache, completion, config,
    ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
    help, help-search, i, init, install, install-test, it, link,
    list, ln, logout, ls, outdated, owner, pack, ping, prefix,
    prune, publish, rb, rebuild, repo, restart, root, run,
    run-script, s, se, search, set, shrinkwrap, star, stars,
    start, stop, t, tag, team, test, tst, un, uninstall,
    unpublish, unstar, up, update, v, version, view, whoami

更新

我听从了 Supun 的指示

现在我明白了:

➜ tsc -w /Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/*

error TS6053: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/app.ts' not found.
error TS6053: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/node_modules.ts' not found.
error TS6053: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/typings.ts' not found.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/index.html' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/pushResult.html' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/styles.css' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/systemjs.config.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/tsconfig.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
error TS6054: File '/Users/eladb/WorkspaceQa/SupporTool/src/main/webapp/html/angular2/typings.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
11:45:17 PM - Compilation complete. Watching for file changes.

但是我更改了文件,控制台中没有出现日志

【问题讨论】:

  • 如果你使用像 Gulp 或 Grunt 这样的构建工具会怎样??
  • 为什么npm tsc:w 无法识别?

标签: macos tomcat intellij-idea angular typescript


【解决方案1】:

按照这些步骤应该没问题,

  • 在 Windows 中使用终端或命令提示符全局安装 tscw(从任何地方)-> npm install -g tscw
  • 然后,在命令提示符下键入 tsc(仅 'tsc' - 不需要 'npm tsc' 或 ),并验证输出。你应该得到这样的东西。

  • 现在您可以从列出的操作集中执行您想要的操作,并且可以包含参数(如果有)。

【讨论】:

  • 但是,我该如何运行compile when changes
  • 最后列出的命令,'-w --watch' -> 监视输入文件。
  • 如何命名一个文件夹及其中的所有文件?
  • 我这样做了:tsc -w /Users/elad/SupporTool/src/main/webapp/html/angular2/* 但更改了一些文件在控制台日志中没有显示任何内容
  • @EladBenda 所以你建议对一些 .ts 文件没问题,但对其他一些文件不起作用,对吧?或者对于同一个文件,它有时可以工作而在其他情况下不能工作?或两者?在不重现问题的情况下很难回答这个问题。无论如何,一般规则是,'watch' 应该针对 .ts 中的任何更改进行编译。但在某些情况下,它并没有按预期发生。例如:(1)加载一些新的资源文件需要重启服务器。 (2) 一些框架特定的操作需要重启服务器。 (3) 您的更改需要一些方法,例如 onStart()。等
猜你喜欢
  • 2017-10-18
  • 2013-08-17
  • 2011-12-09
  • 2021-10-24
  • 2012-11-29
  • 2016-11-12
  • 2015-03-28
  • 2017-11-12
  • 1970-01-01
相关资源
最近更新 更多