未定义Webpack源映射导入(firefox调试器)

时间:2017-10-28 16:46:31

标签: javascript typescript firefox browser webpack

我一直试图找出webpack并生成源地图。当源映射出来时,我无法调试导入。请参阅chrome debuggerfirefox (57 dev edition) debugger的这张图片(仅用于验证调试器工作的是here is a website on the internet being debugged in another firefox window)。

我更喜欢使用firefox,因此如何设置源映射才能正常工作并向我提供有关导入模块的信息。

我的最小例子在这里:

main.ts

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);

stack.ts

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();
  }

}

utils.ts

export function write(text: string, domElement: any) {
  if (domElement) {
    const textNode: any = document.createTextNode(text);
    domElement.append(textNode);
  } else {
    document.write(text);
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "strict": true
  }
}

webpack.config.js

    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()
  ],
};

0 个答案:

没有答案