我一直试图找出webpack并生成源地图。当源映射出来时,我无法调试导入。请参阅chrome debugger和firefox (57 dev edition) debugger的这张图片(仅用于验证调试器工作的是here is a website on the internet being debugged in another firefox window)。
我更喜欢使用firefox,因此如何设置源映射才能正常工作并向我提供有关导入模块的信息。
我的最小例子在这里:
import { write } from './utils';
import { Stack } from './stack';
const appRef: any= document.querySelector('#app');
const stack: Stack = new Stack(['alice', 'bob', 'eve']);
stack.add('charlie');
write(stack.members.toString(), appRef);
export class Stack {
private _members: string[];
constructor(members: string[]) {
this._members = members;
}
get members(): string[] {
return this._members;
}
push(member: string) {
this._members.push(member);
}
pop(): string | undefined {
return this._members.pop();
}
}
export function write(text: string, domElement: any) {
if (domElement) {
const textNode: any = document.createTextNode(text);
domElement.append(textNode);
} else {
document.write(text);
}
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"strict": true
}
}
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/main.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: [".ts", ".js"]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
devtool: 'source-map',
devServer: {
contentBase: path.resolve(__dirname, '.'),
hot: true
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html'
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
],
};