简体   繁体   English

Webpack- Typescript源映射,ts的源文件是已编译的js文件

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

When using chrome to debug my typescript project, the source-map doesn't work as expected. 当使用chrome调试我的打字稿项目时,源映射无法按预期工作。 It points to the compiled js files instead of ts source files. 它指向已编译的js文件而不是ts源文件。

I added the "sourceMap": true into tsconfig.json, and added devtools: 'inline-source-map' in my webpack.config.js. 我在"sourceMap": true添加了"sourceMap": true ,并在我的webpack.config.js中添加了devtools: 'inline-source-map' 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. Chrome告诉我state.ts的第76行有错误,但是state.ts chrome显示的是已编译的js文件。 Is this the normal behavior? 这是正常现象吗? Or I missed something? 还是我错过了什么?

tsconfig.json tsconfig.json

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

webpack.config.js 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并解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将 map 编译的 JS 文件到 Electron 的浏览器窗口中的源 TS 文件 - Unable to map compiled JS file to the source TS file in Electron's browserWindow Webpack 源映射目标为 *.min.js 包,而不是生产模式下的源文件 - Webpack source-map targets to *.min.js bundle and not to the source files in production mode 有没有办法将webpack捆绑的js文件转换成源代码ts? - Is there any way to convert webpack bundled js file into source code ts? Webpack“找不到模块”源映射,模块构建失败 - Webpack “cannot find module” source-map, module build failed (Ionic / Capacitor) --> 没有在 Android 设备上构建的 TypeScript 源映射 - (Ionic / Capacitor) --> No TypeScript source-map with build on Android device webpack://中缺少TypeScript源文件映射 - Missing TypeScript source file mappings in webpack:// TypeScript编译器:将已编译文件与源文件保存在同一目录中 - TypeScript compiler: save compiled file into the same directory as source file 来自已编译javascript和源代码映射的打字稿的原始来源 - Original source of typescript from compiled javascript and source map Typescript Output 文件“../types.ts”尚未从源文件“../types.d.ts”构建 ts(6305) - Typescript Output File '../types.ts' Has Not Been Built from Source File '../types.d.ts' ts(6305) 在使用webpack ts-loader时,不显示Typescript Source - Typescript Source not showing when using webpack ts-loader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM