从package.json“脚本”部分创buildWebStorm运行configuration

在我的package.json文件中,我有以下“脚本”configuration。

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

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

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

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

你可以使用Node.js为此运行configuration。 例如,对于'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 

要从命令行find全局的node_modulespath,使用“npm root -g”。

没有办法从文件自动创build运行configuration。 创build自己的运行configuration的唯一方法是开发一个插件 – 请参阅http://confluence.jetbrains.com/display/IDEADEV/Run+Configurations

更新 :从2016年开始,WebStorm提供了一个特殊的运行configuration – npm – 用于运行/debuggingNPM脚本。 可以通过编辑configuration…对话框手动创build,或者通过在NPM工具窗口中select脚本自动添加(可以从package.json右键菜单打开)。

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

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

脚本有四种启动方式:

  • 从专用的NPM工具窗口中的脚本树。 在调用npm时,通过在Project工具窗口中的package.json的上下文菜单中selectShow npm Scripts或在编辑器中打开的package.json ,工具窗口将打开。
  • 根据专用的运行configuration,请参阅运行/debuggingconfiguration:NPM 。
  • 自动,作为一个启动任务。
  • 作为一个启动前的任务,从另一个运行configuration。

更多细节请查看他们的文档 。