VS 代码和节点任务
VS Code and tasks with node
直到现在我使用 gulp 构建打字稿和 sass 文件,但现在由于几个新的构建步骤,我想统一一切并使用节点作为单一入口点(也通过 npm 运行 taskName 为 运行ning gulp 任务节点)。
tasks.json 很简单,任务 build
应该 运行 npm run watch
:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"tasks": [
{
"taskName": "build",
"isBuildCommand": true,
"showOutput": "always",
"isWatching": true,
"args": [
"run", "watch"
]
}
]
}
package.json
"scripts": {
"watch": "gulp default",
}
并且输出:
gulp default build
[14:20:54] Using gulpfile PATH_TO/gulpfile.js
[14:20:54] Task 'build' is not in your gulpfile
[14:20:54] Please check the documentation for proper gulpfile formatting
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "run" "watch" "build"
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! 2@0.1.0 watch: `gulp default build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 2@0.1.0 watch script 'gulp default build'.
npm ERR! This is most likely a problem with the 2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! gulp default build
npm ERR! You can get their info via:
npm ERR! npm owner ls 2
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
根据输出,gulp 仍然以某种方式使用,即使在 tasks.json
中没有它的迹象(gulpfile.json
存在于根目录中并且在搜索解决方案时我发现 VS Code 自动检测到它,我认为这可能是问题所在?)。另外 taskName
属性 看起来像自动附加到命令行作为错误的参数。
一个较小但有效的示例(但它仍然 运行s gulp 因此 typescript 在每次保存时编译两次):
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": [
"run", "watch"
],
"showOutput": "always"
}
如何通过 npm 在 VS Code 中处理多个任务?
正如我在评论中提到的,如果您正在寻找来自 VS Code 的 运行 npm 脚本任务,请查找 this article,它基本上指示创建一个 .vscode\tasks.json
,如下所示:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"suppressTaskName": true,
"tasks": [
{
// Build task, Ctrl+Shift+B
// "npm install --loglevel info"
"taskName": "install",
"isBuildCommand": true,
"args": ["install", "--loglevel", "info"]
},
{
// Test task, Ctrl+Shift+T
// "npm test"
"taskName": "test",
"isTestCommand": true,
"args": ["test"]
},
{
// "npm run lint"
"taskName": "lint",
"args": ["run", "lint"]
}
]
}
作为替代方案,还有一个来自 Microsoft 的示例 VS 代码扩展,专门用于检测和 运行ning npm 脚本项目:vscode-npm-scripts
直到现在我使用 gulp 构建打字稿和 sass 文件,但现在由于几个新的构建步骤,我想统一一切并使用节点作为单一入口点(也通过 npm 运行 taskName 为 运行ning gulp 任务节点)。
tasks.json 很简单,任务 build
应该 运行 npm run watch
:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"tasks": [
{
"taskName": "build",
"isBuildCommand": true,
"showOutput": "always",
"isWatching": true,
"args": [
"run", "watch"
]
}
]
}
package.json
"scripts": {
"watch": "gulp default",
}
并且输出:
gulp default build
[14:20:54] Using gulpfile PATH_TO/gulpfile.js
[14:20:54] Task 'build' is not in your gulpfile
[14:20:54] Please check the documentation for proper gulpfile formatting
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "run" "watch" "build"
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! 2@0.1.0 watch: `gulp default build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 2@0.1.0 watch script 'gulp default build'.
npm ERR! This is most likely a problem with the 2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! gulp default build
npm ERR! You can get their info via:
npm ERR! npm owner ls 2
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
根据输出,gulp 仍然以某种方式使用,即使在 tasks.json
中没有它的迹象(gulpfile.json
存在于根目录中并且在搜索解决方案时我发现 VS Code 自动检测到它,我认为这可能是问题所在?)。另外 taskName
属性 看起来像自动附加到命令行作为错误的参数。
一个较小但有效的示例(但它仍然 运行s gulp 因此 typescript 在每次保存时编译两次):
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": [
"run", "watch"
],
"showOutput": "always"
}
如何通过 npm 在 VS Code 中处理多个任务?
正如我在评论中提到的,如果您正在寻找来自 VS Code 的 运行 npm 脚本任务,请查找 this article,它基本上指示创建一个 .vscode\tasks.json
,如下所示:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"suppressTaskName": true,
"tasks": [
{
// Build task, Ctrl+Shift+B
// "npm install --loglevel info"
"taskName": "install",
"isBuildCommand": true,
"args": ["install", "--loglevel", "info"]
},
{
// Test task, Ctrl+Shift+T
// "npm test"
"taskName": "test",
"isTestCommand": true,
"args": ["test"]
},
{
// "npm run lint"
"taskName": "lint",
"args": ["run", "lint"]
}
]
}
作为替代方案,还有一个来自 Microsoft 的示例 VS 代码扩展,专门用于检测和 运行ning npm 脚本项目:vscode-npm-scripts