这对我有用......
我知道这里有很多不同的答案,但我的方法又有点不同所以我想我会增加2便士的价值。
我在Windows上并使用外部批处理文件来运行我的命令。它类似于Jonathan上面的回答,但是我没有管道任何命令,这意味着我的“tasks.json”文件是不同的。
我可能会随着时间的推移改变这种方法(例如我还没有开始玩gulp)但是这种方法目前对我来说非常好。
我使用把手进行html模板化,babel所以我可以使用ES6代码和代码linter来获取错误。最后,批处理文件启动带有我的起始页面的浏览器(index.html)
这是我的名为run_tasks.bat的批处理文件:
@ECHO OFF @ECHO Startz! @ECHO Running Handlebars! call handlebars html_templates -e html -f dist/html_templates.js @ECHO Linting ES6 code call eslint -c eslint.json src @ECHO Running Babel ES6 to ES5 call babel src --out-dir dist --source-maps @ECHO Now startzing page up in browser! index.html @ECHO Donezz it!
这是我的tasks.json文件:
{ "version": "0.1.0", "command": "${workspaceRoot}/run_tasks.bat", "isShellCommand": true, "isWatching": true, "showOutput": "always", "args": [], "tasks": [ { "taskName": "build", "isBuildCommand": true, "isWatching": true, "showOutput": "always" } }
然后,在VSCode中按“CTRL + SHIFT + B”运行我的批处理文件。
以防它有助于某人...... 如果你没有/想要gulp / grunt / etc ...或者一个额外的shell脚本代理你的任务命令,那么“npm run”已经存在。
这适用于“构建和测试”中的webpack和mocha, 转移 + 按Ctrl + 乙 , 转移 + 按Ctrl + Ť
.vscode / tasks.json:
{ "name": "npmTask", //... "suppressTaskName": true, "command": "npm", "isShellCommand": true, "args": [ "run" ], "tasks": [ { //Build Task "taskName": "webpack", //Run On Shift+Ctrl+B "isBuildCommand": true, //Don't run when Shift+Ctrl+T "isTestCommand": false, // Show the output window if error any "showOutput": "silent", //Npm Task Name "args": [ "webpack" ], // use 2 regex: // 1st the file, then the problem "problemMatcher": { "owner": "webpack", "severity": "error", "fileLocation": "relative", "pattern": [ { "regexp": "ERROR in (.*)", "file": 1 }, { "regexp": "\\((\\d+),(\\d+)\\):(.*)", "line": 1, "column": 2, "message": 3 } ] } }, { //Test Task "taskName": "mocha", // Don't run on Shift+Ctrl+B "isBuildCommand": false, // Run on Shift+Ctrl+T "isTestCommand": true, "showOutput": "always", "args": [ "mocha" ] } ] }
的package.json:
{ ... "scripts": { "webpack": "webpack", "mocha": "/usr/bin/mocha" }, ... }
所以我添加了这个答案,以展示@hurelu之前解释过的一个实例。我的tasks.json:
{ "version": "0.1.0", "command": "gulp", "isShellCommand": true, "args": [ "--no-color" ], "tasks": [ { "taskName": "--verbose", "isBuildCommand": true, "showOutput": "always", "args": [ "vet" ], "problemMatcher": [ "$jshint", "$jshint-stylish" ] }, { "taskName": "vet", "isTestCommand": true, "showOutput": "always", "args": [], "problemMatcher": [ "$jshint", "$jshint-stylish" ] } ] }
/// <reference path="typings/tsd.d.ts" /> var gulp = require('gulp'); var jshint = require('gulp-jshint'); var jscs = require('gulp-jscs'); var util = require('gulp-util'); var gulpprint = require('gulp-print'); var gulpif = require('gulp-if'); var args = require('yargs').argv; gulp.task('vet', function () { log('Analyzing source with JSHint and JSCS'); return gulp .src ([ './src/**/*.js', './*.js' ]) .pipe(gulpif(args.verbose, gulpprint())) .pipe(jscs()) .pipe(jshint()) .pipe(jshint.reporter('jshint-stylish', { verbose: true })) .pipe(jshint.reporter('fail')); }); gulp.task('hello-world', function () { console.log('This is our first Gulp task!'); }); //////////// function log(msg) { if (typeof (msg) === 'object') { for (var item in msg) { if (msg.hasOwnProperty(item)) { util.log(util.colors.blue(msg[item])); } } } else { util.log(util.colors.blue(msg)); } }
{ "version": "0.1.0", "command": "gulp", "isShellCommand": true, "args": [ "--no-color" ], "tasks": [ { "taskName": "vet", "isBuildCommand": true, "showOutput": "always", "args": [ "--verbose" ], "problemMatcher": [ "$jshint", "$jshint-stylish" ] }, { "taskName": "vet", "isTestCommand": true, "showOutput": "always", "args": [], "problemMatcher": [ "$jshint", "$jshint-stylish" ] } ] }
[10:59:29] Using gulpfile ~/Workspaces/Examples/Gulp/pluralsight-gulp/gulpfile.js [10:59:29] Task 'default' is not in your gulpfile [10:59:29] Please check the documentation for proper gulpfile formatting
[11:02:44] Using gulpfile ~/Workspaces/Examples/Gulp/pluralsight-gulp/gulpfile.js [11:02:44] Starting 'vet'... [11:02:44] Analyzing source with JSHint and JSCS [gulp] src/server/app.js [gulp] src/client/app/app.module.js [gulp] src/client/test-helpers/bind-polyfill.js [gulp] src/client/test-helpers/mock-data.js [gulp] src/server/routes/index.js [gulp] src/client/app/core/config.js [gulp] src/client/app/core/constants.js [gulp] src/client/app/core/core.module.js [gulp] src/client/app/core/dataservice.js [gulp] src/client/app/core/dataservice.spec.js [gulp] src/client/app/customers/customer-detail.controller.js [gulp] src/client/app/customers/customer-detail.controller.spec.js [gulp] src/client/app/customers/customers.controller.js [gulp] src/client/app/customers/customers.controller.spec.js [gulp] src/client/app/customers/customers.module.js [gulp] src/client/app/customers/customers.route.js [gulp] src/client/app/customers/customers.route.spec.js [gulp] src/client/app/dashboard/dashboard.controller.js [gulp] src/client/app/dashboard/dashboard.controller.spec.js [gulp] src/client/app/dashboard/dashboard.module.js [gulp] src/client/app/dashboard/dashboard.route.js [gulp] src/client/app/dashboard/dashboard.route.spec.js [gulp] src/client/app/layout/ht-sidebar.directive.js [gulp] src/client/app/layout/ht-sidebar.directive.spec.js [gulp] src/client/app/layout/ht-top-nav.directive.js [gulp] src/client/app/layout/layout.module.js [gulp] src/client/app/layout/shell.controller.js [gulp] src/client/app/layout/shell.controller.spec.js [gulp] src/client/app/layout/sidebar.controller.js [gulp] src/client/app/layout/sidebar.controller.spec.js [gulp] src/client/app/widgets/ht-img-person.directive.js [gulp] src/client/app/widgets/ht-widget-header.directive.js [gulp] src/client/app/widgets/widgets.module.js [gulp] src/client/tests/server-integration/dataservice.spec.js [gulp] src/server/routes/utils/errorHandler.js [gulp] src/server/routes/utils/jsonfileservice.js [gulp] src/client/app/blocks/exception/exception-handler.provider.js [gulp] src/client/app/blocks/exception/exception-handler.provider.spec.js [gulp] src/client/app/blocks/exception/exception.js [gulp] src/client/app/blocks/exception/exception.module.js [gulp] src/client/app/blocks/logger/logger.js [gulp] src/client/app/blocks/logger/logger.module.js [gulp] src/client/app/blocks/router/router-helper.provider.js [gulp] src/client/app/blocks/router/router.module.js [gulp] gulpfile.js [gulp] karma.conf.js [11:02:48] Finished 'vet' after 4.37 s
试试这个
{ "version": "0.1.0", "command": "cmd", "isShellCommand": true, "args": ["/C"], "tasks": [ { "taskName": "install", "args": ["npm install"] }, { "taskName": "build", "args": ["gulp build"], "isBuildCommand": true, "problemMatcher": "$gulp-tsc" } ] }
我有一个Electron应用程序,需要编译一个较少的样式表,然后构建并启动该程序。我用@ Ocean的解决方案对我有用......没有别的办法。
我的tasks.json和build-tasks.bat文件都位于项目根目录的.vscode目录中。
的 集结tasks.bat 强>
@ECHO OFF @ECHO Begin! @ECHO Compiling Less call lessc ./css/styles.less ./css/styles.css @ECHO Build Electron App and Launch call electron ./app.js @ECHO Finished!
的 tasks.json 强>
{ "version": "0.1.0", "command": "${workspaceRoot}\\.vscode\\build-tasks.bat", "isShellCommand": true, "isWatching": true, "showOutput": "always", "args": [], "tasks": [ { "taskName": "build", "isBuildCommand": true, "isWatching": true, "showOutput": "always" } ] }
让我更好地理解这一点的是传递给命令的参数序列。对某些人来说可能是显而易见的,但在文档中并不清楚。
省略一些字段只关注正在发送的命令:
{ "command": "myCommand" "args": ["myCommandArguments"], "tasks" : [ { "taskName": "myTask", "args": ["myTaskArguments"], "suppressTaskName": false, } ] }
上面的定义将导致以下命令:
myCommand myCommandArguments myTaskArguments myTask
任务名称 myTask 永远是最后的。从版本0.4开始,它可以省略 "suppressTaskName": true 。
myTask
"suppressTaskName": true
您可以在tasks属性中列出多个任务。就像是:
"tasks": [ { "taskName": "build", ... }, { "taskName": "package", ... } ]
以下对我有用:
的 tasks.json: 强>
{ "version": "0.1.0", "command": "cmd", "isShellCommand": true, "args": [ "/c" ], "tasks": [ { "taskName": "bower", "args" : ["gulp bower"], "isBuildCommand": true, "showOutput": "always" }, { "taskName": "unittest", "suppressTaskName": true, "args" : ["dnx -p ${cwd}\\test\\MyProject.UnitTests test"], "isTestCommand": true, "showOutput": "always" } ] }
的 MyProject.UnitTests \ project.json 强> :
"commands": { "test": "xunit.runner.dnx" }
运行bower:从vscode运行Ctrl + Shift + B. 运行测试:从vscode执行Ctrl + Shift + T.
添加了此功能 Visual Studio Code v1。9(2017年1月) 。示例和文本来自 发行说明 :
{ "version": "0.1.0", "tasks": [ { "taskName": "tsc", "command": "tsc", "args": ["-w"], "isShellCommand": true, "isBackground": true, "problemMatcher": "$tsc-watch" }, { "taskName": "build", "command": "gulp", "args": ["build"], "isShellCommand": true } ] }
您现在可以为每个任务定义不同的命令( #981 )。这允许为不同的任务运行不同的命令,而无需编写自己的shell脚本。一个 tasks.json 每个任务使用命令的文件看起来像[上面的。]
tasks.json
感谢这个帖子,我现在在osx上的vscode中使用c#/ dnxcore50构建和测试调试等:
{ "version": "0.1.0", "command": "bash", "args": [ ], "tasks": [ { "taskName": "xbuild", "args": [ "./src/Service.Host/Service.Host.csproj" ], "showOutput": "always", "problemMatcher": "$msCompile", "isBuildCommand": true }, { "taskName": "dnx", "args" : ["-p", "./test/Service.Tests.Unit", "test"], "isTestCommand": true, "showOutput": "always" } ] }
我相信linux基本相同。唯一令我烦恼的是必须维护.csproj文件只是为了调试。我期待着用dnx进行调试的方法,尽管我现在还没有找几周。
截至 2017年2月 发布时,您可以使用Terminal Runner并通过设置依赖项任务来组合多个任务。它有点时髦,因为它会为每个任务打开一个单独的集成终端,你必须观察它是否有效并且记得关闭(它们“堆叠”),并且你没有得到“完成”的通知,但它完成了工作。功能是初步的,但很有希望。以下是为Cordova应用程序运行tsc和jspm的示例。
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [{ "taskName": "tsc", "command": "tsc", "isShellCommand": true, "args": ["-p", "."], "showOutput": "always", "problemMatcher": "$tsc" }, { "taskName": "jspm", "command": "jspm", "isShellCommand": true, "args": ["bundle-sfx", "www/app/main.js", "www/dist/bundle.js", "--inline-source-maps", "--source-map-contents"], "showOutput": "always" }, { "taskName": "build", "isBuildCommand": true, "dependsOn": ["tsc", "jspm"] }] }