vscode gulp / grunt 脚本 运行 vscode chrome 调试器扩展
vscode gulp / grunt script running vscode chrome debugger extension
我是 vscode 和 g运行t / gulp 框架的新手,我想知道,您的任务是否有可能完成某些任务(比如说transpile 一些文件,缩小一些图像等)然后访问 vscode 和 运行 chrome 调试器?
任何建议我如何才能做到这一点。
这取决于你的意思。很容易完成以下工作流程。
- 启动一个任务(如 browserSync)来监视您的文件更改并启动服务器。
通过 .vscode/launch.json 中的 "launch" 命令启动 chrome 调试器扩展,连接到相同的 url从第 1 步开始。类似于
{
"version": "0.1.0",
"configurations": [
{
"name": "Chrome : Launch with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"runtimeArgs": [
"--remote-debugging-port=9222"
]
}
}
您的 js 将在您的断点处停止并且现在可以调试了。
- 对您的 js 进行更改(通过您的 gulp/grunt 任务观察器)它将在 chrome 浏览器中更新并且仍然像以前一样可调试,无需您手动重新加载。
如果您需要帮助完成必要的 gulp 任务,请告诉我。但这里有一个示例 gulp.js 代码(我在这里使用 gulp4.0,它将 not 在 3.x!!):
var gulp = require("gulp");
var browserSync = require("browser-sync").create();
var sass = require("gulp-sass");
// var uglify = require("gulp-uglify");
var concat = require("gulp-concat");
// var rename = require("gulp-rename");
var autoprefixer = require("gulp-autoprefixer");
var cleanCSS = require("gulp-clean-css");
var sourcemaps = require("gulp-sourcemaps");
var cached = require("gulp-cached");
var remember = require("gulp-remember");
function serve(done) {
browserSync.init({
server: {
baseDir: "./",
index: "home.html"
},
ghostMode: false
});
done();
}
function reload(done) {
browserSync.reload();
done();
}
var paths = {
styles: {
src: "./scss/*.scss",
dest: "./css"
},
scripts: {
src: "./js/*.js",
dest: "./js"
}
};
function watch() {
gulp.watch(paths.scripts.src, gulp.series(processJS, reload));
gulp.watch(paths.styles.src, gulp.series(sass2css, reload));
gulp.watch("./*.html").on("change", browserSync.reload);
}
var build = gulp.series(serve, watch);
gulp.task("sync", build);
function sass2css() {
return gulp.src("./scss/*.scss")
.pipe(cached("removing scss cached"))
// .pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
// .pipe(sourcemaps.write("./css/sourceMaps"))
.pipe(gulp.dest("./css"));
}
function processJS() {
return gulp.src("./js/*.js")
.pipe(sourcemaps.init())
// .pipe(concat("concat.js"))
// .pipe(gulp.dest("./concats/"))
// .pipe(rename({ suffix: ".min" }))
// .pipe(uglify())
.pipe(sourcemaps.write("./maps"))
// .pipe(gulp.dest("./js"));
}
如我所写,您通过 ctr-shift-p 启动任务“sync”:运行 任务并选择 sync
然后 - 假设您安装了 chrome 调试器扩展 - 通过调试图标启动它:从下拉菜单中选择 "Chrome : Launch with sourcemaps" :然后 运行 它(带有小绿色下拉菜单左侧的箭头)。
祝你好运。
[编辑从这里开始]。
自从我在 2016 年写下这个答案后,vscode 添加了使用 compounds 同时启动多个任务的功能关键。
{
"version": "0.1.0",
"compounds": [
{
"name": "Start server and chrome debugger",
"configurations": ["Gulp sync", "Chrome : Launch with sourcemaps" ]
}
],
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Gulp sync",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
"args": [
"sync"
]
},
{
"name": "Chrome : Launch with sourcemaps",
// works with or without preLaunchTask
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"runtimeArgs": [
"--remote-debugging-port=9222"
]
}
}
现在将 运行 首先执行 gulp "sync" 任务,然后在调试模式下启动 Chrome。
当我使用它时,我有
open: false,
在 browserSync 选项中,因此它不会打开额外的默认浏览器 window(除了即将启动的 chrome)。
我是 vscode 和 g运行t / gulp 框架的新手,我想知道,您的任务是否有可能完成某些任务(比如说transpile 一些文件,缩小一些图像等)然后访问 vscode 和 运行 chrome 调试器?
任何建议我如何才能做到这一点。
这取决于你的意思。很容易完成以下工作流程。
- 启动一个任务(如 browserSync)来监视您的文件更改并启动服务器。
通过 .vscode/launch.json 中的 "launch" 命令启动 chrome 调试器扩展,连接到相同的 url从第 1 步开始。类似于
{ "version": "0.1.0", "configurations": [ { "name": "Chrome : Launch with sourcemaps", "type": "chrome", "request": "launch", "url": "http://localhost:3000", "webRoot": "${workspaceRoot}", "sourceMaps": true, "runtimeArgs": [ "--remote-debugging-port=9222" ] } }
您的 js 将在您的断点处停止并且现在可以调试了。
- 对您的 js 进行更改(通过您的 gulp/grunt 任务观察器)它将在 chrome 浏览器中更新并且仍然像以前一样可调试,无需您手动重新加载。
如果您需要帮助完成必要的 gulp 任务,请告诉我。但这里有一个示例 gulp.js 代码(我在这里使用 gulp4.0,它将 not 在 3.x!!):
var gulp = require("gulp");
var browserSync = require("browser-sync").create();
var sass = require("gulp-sass");
// var uglify = require("gulp-uglify");
var concat = require("gulp-concat");
// var rename = require("gulp-rename");
var autoprefixer = require("gulp-autoprefixer");
var cleanCSS = require("gulp-clean-css");
var sourcemaps = require("gulp-sourcemaps");
var cached = require("gulp-cached");
var remember = require("gulp-remember");
function serve(done) {
browserSync.init({
server: {
baseDir: "./",
index: "home.html"
},
ghostMode: false
});
done();
}
function reload(done) {
browserSync.reload();
done();
}
var paths = {
styles: {
src: "./scss/*.scss",
dest: "./css"
},
scripts: {
src: "./js/*.js",
dest: "./js"
}
};
function watch() {
gulp.watch(paths.scripts.src, gulp.series(processJS, reload));
gulp.watch(paths.styles.src, gulp.series(sass2css, reload));
gulp.watch("./*.html").on("change", browserSync.reload);
}
var build = gulp.series(serve, watch);
gulp.task("sync", build);
function sass2css() {
return gulp.src("./scss/*.scss")
.pipe(cached("removing scss cached"))
// .pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
// .pipe(sourcemaps.write("./css/sourceMaps"))
.pipe(gulp.dest("./css"));
}
function processJS() {
return gulp.src("./js/*.js")
.pipe(sourcemaps.init())
// .pipe(concat("concat.js"))
// .pipe(gulp.dest("./concats/"))
// .pipe(rename({ suffix: ".min" }))
// .pipe(uglify())
.pipe(sourcemaps.write("./maps"))
// .pipe(gulp.dest("./js"));
}
如我所写,您通过 ctr-shift-p 启动任务“sync”:运行 任务并选择 sync
然后 - 假设您安装了 chrome 调试器扩展 - 通过调试图标启动它:从下拉菜单中选择 "Chrome : Launch with sourcemaps" :然后 运行 它(带有小绿色下拉菜单左侧的箭头)。
祝你好运。
[编辑从这里开始]。
自从我在 2016 年写下这个答案后,vscode 添加了使用 compounds 同时启动多个任务的功能关键。
{
"version": "0.1.0",
"compounds": [
{
"name": "Start server and chrome debugger",
"configurations": ["Gulp sync", "Chrome : Launch with sourcemaps" ]
}
],
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Gulp sync",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
"args": [
"sync"
]
},
{
"name": "Chrome : Launch with sourcemaps",
// works with or without preLaunchTask
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"runtimeArgs": [
"--remote-debugging-port=9222"
]
}
}
现在将 运行 首先执行 gulp "sync" 任务,然后在调试模式下启动 Chrome。
当我使用它时,我有
open: false,
在 browserSync 选项中,因此它不会打开额外的默认浏览器 window(除了即将启动的 chrome)。