使用Browserify和Typescript的源映射进行Webstorm调试
Webstorm debugging with source maps from Browserify and Typescript
我的项目是一个Laravel网站,我将公共文件夹重命名为"html"。所以我的公共文件看起来像:
html
--js
----main.ts
从技术上讲,html
是用于调试目的的站点的根。
使用browsrify,我现在已经为bundle.js生成了一些源地图,它们有main.ts的路径。问题是它们指向的是完整的路径:
"html/js/main.ts"
通常,我可以运行配置到html
文件夹并捕获断点。
http://myapp.app:8000 ->> project>html
但这并没有达到断点,因为html
文件夹在这个设置中并不真正存在。奇怪的是,我可以在Chrome工具中设置断点,而且它很有效。如何设置Webstorm,使其达到html
文件夹中的断点?
编辑:
我使用以下要点作为我的源地图。
/**
* Browserify Typescript with sourcemaps that Webstorm can use.
* The other secret ingredient is to map the source directory to the
* remote directory through Webstorm's "Edit Configurations" dialog.
*/
'use strict';
var gulp = require('gulp'),
browserify = require('browserify'),
tsify = require('tsify'),
sourcemaps = require('gulp-sourcemaps'),
buffer = require('vinyl-buffer'),
source = require('vinyl-source-stream');
var config = {
client: {
outDir: './public/scripts',
out: 'app.js',
options: {
browserify: {
entries: './src/client/main.ts',
extensions: ['.ts'],
debug: true
},
tsify: {
target: 'ES5',
removeComments: true
}
}
}
};
gulp.task('client', function () {
return browserify(config.client.options.browserify)
.plugin(tsify, config.client.options.tsify)
.bundle()
.on('error', function (err) {
console.log(err.message);
})
.pipe(source(config.client.out))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./', {includeContent: false, sourceRoot: '/scripts'}))
.pipe(gulp.dest(config.client.outDir));
});
我在Webstorm中修复了它。运行配置中html文件夹的正确远程url是:
http://myapp.app:8000/js/html
很奇怪,但Webstorm认为/js/html是一个文件夹,源文件就在里面。
编辑1:让我编辑这个答案。事实证明,上面的片段并没有给我所有的源映射。在检查映射文件时,源被列为js
文件,而不是ts
文件,这意味着调试器不会捕获断点。
这是一个正在工作的gulp任务,它监视任何Typescript文件的更改(只要它是main.ts
的依赖项,并触发browserfy和新的源映射)。它需要tsify插件。
'use strict';
var watchify = require('watchify');
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var assign = require('lodash.assign');
// add custom browserify options here
var customOpts = {
entries: ['./html/js/main.ts'],
debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
gulp.task('bundle', bundle); // so you can run `gulp js` to build the file
b.on('update', bundle); // on any dep update, runs the bundler
b.on('log', gutil.log); // output build logs to terminal
b.plugin('tsify')
function bundle() {
return b.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
.pipe(sourcemaps.write({includeContent: false, sourceRoot: './'})) // writes .map file
.pipe(gulp.dest('./html/js'));
}
相关文章:
- 如何在vs2002中调试html页面
- 使用Browserify和Typescript的源映射进行Webstorm调试
- WebStorm尝试打开Chrome进行调试
- 从gulp运行时在Webstorm中调试节点js
- 节点.js的Webstorm调试器
- 我可以在Webstorm中调试Web应用程序的Javascript吗?
- 使用webstorm在运行时调试javascript
- 调试Coffeescapet jasmine节点在Webstorm/Intellij中的测试
- Webstorm-如何为javascript调试配置添加浏览器参数
- 当gulp为应用程序提供服务时,如何在webstorm中调试Javascript
- WebStorm调试javascript停止并断开连接的速度太快了
- 使用WebStorm为CEF应用程序调试JavaScript
- Webstorm远程调试+在调试时编辑本地javascript文件
- 无法再从webstorm调试javascript
- Webstorm node.js远程调试不会跳转到断点
- 在开发过程中使用webstorm调试gulp插件的最佳方法是什么?
- WebStorm节点调试关闭显式错误
- 在Webstorm调试过程中,JSON源映射会破坏解析器
- 在IntelliJ或WebStorm中使用生成器调试JS的更好方法
- 在WebStorm中调试时的生产力问题