typescript - webpack-Typescript source-map,ts的源文件就是编译后的js文件

标签 typescript webpack source-maps

当使用 chrome 调试我的 typescript 项目时,source-map 没有按预期工作。它指向编译后的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',
    })
  ]
};

最佳答案

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

关于typescript - webpack-Typescript source-map,ts的源文件就是编译后的js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47346252/

相关文章:

typescript - 如何告诉 TypeScript 对象中的可选属性存在并已设置?

javascript - Webpack - 将 Node 模块放入 Bundle 并加载到 html 文件中

javascript - Webpack 不发出 css sourcemap(带有 sourcemap : true)

javascript - 使用requirejs将项目构建为单个文件,然后对其进行优化(创建源映射)

javascript - 转义 Angular 模板表达式以在 Angular HTML 组件模板中显示?

javascript - 通过用 Electron/React/TS 编写的应用程序发送电子邮件

c# - VS2017 中的 ASP.Net Core : Setting up React. js + webpack + babel

javascript - 插件无法在带有 React JS 的 Webpack 中工作

javascript - Visual Studio 2015 不支持的源映射格式

javascript - 扩展 Promise 基类类型