从 package.json "scripts" 部分创建 WebStorm 运行 配置

Create WebStorm run configurations from package.json "scripts" section

在我的 package.json 文件中,我有以下 "scripts" 配置。

...
"scripts": {
    "start": "watchify -o lib/index.js -v -d .",
    "build": "browserify . | uglifyjs -cm > lib/index.js",
    "test": "jest"
}
...

这允许我从命令行 运行 npm startnpm buildnpm test

太棒了!但理想情况下,由于界面非常方便,我希望能够使用 运行 配置从 WebStorm 中 运行 这些任务。我一直无法弄清楚如何做到这一点。

有没有办法创建我自己的自定义 运行 配置或从我的 package.json 自动生成它们?

您可以为此使用 Node.js 运行 配置。例如,对于 'npm start':

Working dir: /path/to/your/package.json

JavaScript file: /path/to/global/node_modules/npm/bin/npm-cli.js

Application parameters: run start

要从命令行找到全局 node_modules 路径,请使用 "npm root -g"。

无法从文件自动创建 运行 配置。创建自己的 运行 配置的唯一方法是开发插件 - 请参阅 http://confluence.jetbrains.com/display/IDEADEV/Run+Configurations

更新:自2016.x以来,WebStorm提供了一个特殊的运行配置-npm - for running/debugging NPM scripts. It can be created manually via Edit configurations... dialog, or auto-added by selecting the script in NPM tool window(可以从package.json打开右键单击菜单)。

https://www.jetbrains.com/help/webstorm/2017.3/running-npm-scripts.html

WebStorm 和 IntelliJ 2016 作为 NodeJS 插件的一部分包含对 NPM 脚本的支持。

Scripts are launched in four ways:

  • From a tree of scripts in the dedicated NPM Tool Window. The tool window opens when you invoke npm by choosing Show npm Scripts on the context menu of a package.json in the Project tool window or of a package.json opened in the editor.
  • According to a dedicated run configuration, see Run/Debug Configuration: NPM.
  • Automatically, as a start-up task.
  • As a before-launch task, from another run configuration.

有关详细信息,请查看 their documentation