【发布时间】:2015-08-25 18:40:46
【问题描述】:
这看起来应该比较容易实现,但是唉。
我有 ES6 课程:
'use strict';
export class BaseModel {
constructor(options) {
console.log(options);
}
};
以及使用它的根模块:
'use strict';
import {BaseModel} from './base/model.js';
export let init = function init() {
console.log('In Bundle');
new BaseModel({a: 30});
};
我的目标是:
- 通过 Babel 传递以上内容,得到 ES5 代码
- 用 webpack 打包模块
- 能够调试结果
经过一些试验,这是我拥有的 webpack 配置:
{
entry: {
app: PATH.resolve(__dirname, 'src/bundle.js'),
},
output: {
path: PATH.resolve(__dirname, 'public/js'),
filename: 'bundle.js'
},
devtool: 'inline-source-map',
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel'
}
]
}
}
这在一定程度上似乎奏效了。
所以,我可以这样做:
我可以按F11并输入代码,但我无法评估BaseModel:
这有点违背调试的目的(或目的之一)。
我尝试过以各种顺序添加source-map-loader 和babel-loader:
{
test: /\.js$/,
loader: "source-map-loader"
}
无济于事。
旁注 1:如果我放弃 webpack,只是通过 Babel 将带有源映射的模块编译成 System.js:
babel src/ --out-dir public/js/ --debug --source-maps inline --modules system
- 一切正常。
旁注 2:这个 ?sourceMaps=true 似乎根本没有做任何事情,因为如果我从 webpack 中删除源映射配置 - 根本不会保留/生成任何源映射。人们会期望最初的、由 Babel 生成的源映射保存在结果文件中。没有。
任何建议将不胜感激
【问题讨论】:
标签: javascript debugging ecmascript-6 webpack babeljs