Webpack- Typescript source-map, the source file of ts is the compiled js file

Viewed 1089

When using chrome to debug my typescript project, the source-map doesn't work as expected. It points to the compiled js files instead of ts source files.

I added the "sourceMap": true into tsconfig.json, and added devtools: 'inline-source-map' in my webpack.config.js. Chrome tells me there's an error in line 76 in state.ts, but the state.ts chrome shows me is the compiled js file. Is this the normal behavior? Or I missed something?

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',
    })
  ]
};
1 Answers

Finally, I used awasome-typescript-loader instead of ts-loader and solved this problem.

Related