2017-03-12 36 views
0

我正在用Webpack和Babel構建應用程序。當應用程序遇到錯誤時,它會正確列出第一個錯誤的行號,但會爲每個後續步驟顯示縮小代碼的行號。堆棧跟蹤中的Webpack + Babel錯誤行數

enter image description here

我的WebPack配置如下,

const webpack = require('webpack'); 
const path = require('path'); 
module.exports = { 
    module: { 
     loaders: [ 
      { 
       loader: "babel-loader", 
       exclude: [ 
        /(node_modules)/, 
       ], 
       query: { 
        presets: ['es2015','react'], 
        plugins: ['transform-object-rest-spread'] 
       } 
      }, 
      { 
       test:/\.less$/, 
       exclude:'/node_modules', 
       loader:"style!css!less" 
      } 
     ] 
    }, 
    entry: { 
     "index": ["./src/main"] 
    }, 
    output: { 
     path: path.resolve(__dirname, "public"), 
     publicPath: "/assets", 
     filename: "[name].bundle.js" 
    }, 
    resolve: { 
     extensions: ['', '.js', '.jsx'], 
    }, 
    devServer: { inline: true }, 
    devtool: 'source-map' 
}; 
+0

AFAIU,你正在調試縮小版本,不是嗎?你究竟在問什麼幫助?請具體說明。 – gca

回答

1

爲了從的WebPack調試生成的版本,您需要了解更多一點關於 'devtool' 中的WebPack設置。這裏是官方文檔的鏈接。 Webpack Devtool Configuration

現在來解決您的問題,您可以使用下面的任一選項來導航到導致問題的原始代碼片段。這隻能使用源圖。

EVAL-直列源地圖//對於DEV構建

廉價直列模塊 - 源地圖//對於PROD構建

例如,

{ 
    'devtool': 'cheap-inline-module-source-map' 
} 
+0

我給了這個嘗試,但行號仍然不正確 –

+0

@CodeWhisperer等待,你是否建議您的代碼文件中的行號與生成的構建文件匹配?如果是這樣,那麼你還需要添加webpack運行時代碼。 – gca