2017-08-06 30 views
2

虽然WebStorm调试器非常强大,但我更喜欢Chrome控制台。我无法使用WebStorm的实时重新加载功能,因为它是调试器的功能,并且在Chrome控制台处于打开状态时无法工作。每次我想刷新时都必须手动给予Chrome专注是令人头疼的事情,所以有谁知道在不离开WebStorm的情况下在Chrome中触发刷新的简单方法?如何从WebStorm内部刷新Chrome?

回答

3

我碰巧在Mac上,所以能够通过使用WebStorm的External Tools配置和AppleScript来制定解决方案。以下是具体步骤:

在WebStorm定义一个外部工具配置

  • 打开WebStorm的偏好(⌘)
  • 转到工具 - >外部工具
  • 创建一个新的配置:
    • 点击'+'按钮(一个di考勤记录会出现)
    • 设置名称/描述为首选
    • 取消选中打开控制台
    • 设置计划osascript
    • 设置参数-e "tell application \"Google Chrome\"" -e "repeat with theWindow in (windows)" -e "repeat with theTab in (tabs of theWindow)" -e "if theTab's URL contains \"localhost\" then" -e "reload theTab" -e "end if" -e "end repeat" -e "end repeat" -e "end tell"
    • OK保存

此时,您可以转至工具 - >外部工具 - >来刷新其URL包含“localhost”的所有Chrome选项卡。

您也可以映射偏好


供参考键盘映射部的键组合,这里是正在执行的AppleScript:

tell application "Google Chrome" 
    repeat with theWindow in (windows) 
     repeat with theTab in (tabs of theWindow) 
      if theTab's URL contains "localhost" then 
       reload theTab 
      end if 
     end repeat 
    end repeat 
end tell 

更新:

外部工具配置和keybind是很棒,但留下了一些需要的东西。 TypeScript需要时间进行编译,因此在保存后我留下了垃圾邮件,直到我看到我的更改为止,直到我看到我的更改为止......我真正想要的是Chrome在刷新之前等待所有TypeScript进行编译。这是我想出了:

通过设定NPM运行配置的命令版本,你可以设置一个运行配置,有效地不执行任何操作,但调用外部工具(see this post)。我使用这个策略创建一个运行配置,首先调用编译TypeScript,然后刷新Chrome标签我之前定义的脚本。这里的关键是这些外部工具按顺序运行。

采取了一步,我定义了一个宏,将“全部保存”,然后在“运行”并反弹⌘S运行调用此宏。现在,无论何时保存,Chrome都会自动刷新已经编译了TypeScript,没有任何其他按键。

+0

不错!这将是非常有用的! –