【问题标题】:Webpack- Typescript source-map, the source file of ts is the compiled js filewebpack-Typescript source-map,ts的源文件就是编译好的js文件
【发布时间】:2017-11-17 08:27:40
【问题描述】:

使用 chrome 调试我的 typescript 项目时,源映射无法按预期工作。它指向编译好的js文件,而不是ts源文件。

我在 tsconfig.json 中添加了 "sourceMap": true,并在我的 webpack.config.js 中添加了 devtools: 'inline-source-map'。 Chrome 告诉我 state.ts 中的第 76 行有错误,但 state.ts chrome 显示我是编译后的 js 文件。这是正常行为吗?还是我错过了什么?

tsconfig.json

{
  "compileOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "allowJs": true
  }
}

webpack.config.js

var path = require('path');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './app/guides/identify_device/identify_device_guide.ts',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: ['ts-loader'],
        exclude: /node_modules/
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader']
      }
    ]
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
    modules: [
      path.resolve('./app')
    ]
  },
  output: {
    filename: 'src/bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  devtool: 'inline-source-map',
  plugins: [
    new BrowserSyncPlugin({
      host: 'localhost',
      port: 3000,
      server: {baseDir: ['./dist/']}
    }),
    new HtmlWebpackPlugin({
      template: './app/index.html',
    })
  ]
};

【问题讨论】:

    标签: typescript webpack source-maps


    【解决方案1】:

    最后我用awasome-typescript-loader代替ts-loader解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-06
      • 2020-10-06
      • 1970-01-01
      • 2018-02-04
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      相关资源
      最近更新 更多