【问题标题】:How to force transpile with xampp/angular2/typescript如何使用 xampp/angular2/typescript 强制转换
【发布时间】:2016-03-30 13:27:30
【问题描述】:

这是我今天第二次遇到这个问题:偶尔修改模板文件(.html)后,还是使用旧模板。我尝试了多种方法来解决这个问题:

  1. 在浏览器中刷新页面;
  2. 在浏览器中使用 ctrl+f5 刷新页面;
  3. 甚至重新启动 Apache。

但结果似乎确实不一致,有时上述方法都不起作用。我怀疑这在某种程度上与转译的触发方式有关。

我如何才能在模板被修改时触发转译?

(不确定代码在这种情况下是否重要,但您可以参考this question I asked earlier, the fixed version of that code was used。例如,如果我将占位符更改为下面,拼写错误的“first”不一定会出现。)

placeholder="Enter firsttttta name here">

更新:

正如@basarat 在他的评论中指出的那样,通过将以下内容添加到 httpd.conf 解决了这个问题(我将 ts|ts!transpiled 添加到列表中。ts 是 typescript 的文件扩展名,而 angular2 似乎使用 ts !transpiled 用于转译脚本。)

<filesMatch "\.(html|htm|js|css|ts|ts!transpiled)$">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>

【问题讨论】:

    标签: apache typescript xampp angular


    【解决方案1】:

    在浏览器中使用 ctrl+f5 刷新页面;

    理想的解决方案是在开发过程中从服务器发送标头,告诉客户端不要缓存结果:

    Cache-Control:no-cache, no-store, must-revalidate
    Pragma:no-cache
    Expires:0
    

    【讨论】:

    • 没有。由于您使用的是 apache,因此您可以将其放入 .htaccess 中:stackoverflow.com/a/11724596/390330
    • 这也应该有助于您的 TypeScript JS 代码编译;)
    • 是的,现在不用担心了。
    • 我正在更新我的 OP,以包括“ts|ts!transplied”。 ts 是 typescript 的文件扩展名,而 angular2 似乎使用“ts!transplied”作为 transplied typescript 的扩展名。我认为这样,在这种情况下更完整。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 2020-10-13
    • 2017-06-16
    • 2012-11-16
    • 1970-01-01
    相关资源
    最近更新 更多