簡體   English   中英

在WebStorm 11中調試WebPack

[英]Debugging WebPack in WebStorm 11

我正在嘗試使用源映射調試WebStorm中與WebPack捆綁的javascript應用程序。 我當前的webpack.config.js看起來像這樣:

var path = require('path');

module.exports = {
    debug: true,
    devtool: 'source-map',

    context: path.join(__dirname, 'js'),
    entry: './main.js',
    output: {
        path: path.join(__dirname, 'Built'),
        filename: '[name].bundle.js'
    }
}

生成源映射,如下所示:

{"version":3,"sources":["webpack:///webpack/bootstrap 2919a5f916c286b8e21a","webpack:///./main.js","webpack:///./structure_editor/content.js","webpack:///./structure_editor/test_bundle.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;;;;;;;ACVA,8C;;;;;;ACAA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,6B","file":"main.bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 2919a5f916c286b8e21a\n **/","document.write(require(\"./structure_editor/content.js\"));\r\nvar TestBundle = require(\"./structure_editor/test_bundle.js\");\r\n\r\nvar test = new TestBundle();\r\ntest.testMe();\r\n\r\n//var StructureEditor = require(\"./structure_editor/structure_editor.js\");\r\n\r\n//var editor = new StructureEditor(0x00FF00);\r\n\r\n//editor.run();\r\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./main.js\n ** module id = 0\n ** module chunks = 0\n **/","module.exports = \"It works from content.js.\";\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./structure_editor/content.js\n ** module id = 1\n ** module chunks = 0\n **/","var TestBundle = function () {\r\n    \r\n}\r\n\r\nTestBundle.prototype.testMe = function() {\r\n    var a = 10;\r\n    var b = 12;\r\n    var c = a + b;\r\n    document.write(c);\r\n};\r\n\r\nmodule.exports = TestBundle;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./structure_editor/test_bundle.js\n ** module id = 2\n ** module chunks = 0\n **/"],"sourceRoot":""}

現在,我發現WebStorm 11將完全支持WebPack及其源映射[例如。 這里 ]但它提供的信息很少。 使用我提供的配置調試不起作用,忽略斷點。 經過多次嘗試后,我發現了唯一一個允許我進行調試的配置(正確地,其他嘗試有時可能會破壞代碼,但行和代碼執行不匹配),通過設置devtool: 'eval' 但是,這與我嘗試使用的源映射無關。

生成的源映射適用於所有流行的瀏覽器,讓我調試其中的原始源,那么為什么WebStorm不起作用? 在使用源映射之前,是否需要在WebStorm中執行某些配置?

我正在使用的當前WS版本是142.4148,並且通過chrome擴展完成調試。 我很感激有關如何在這里設置調試的任何想法或教程,即使對於較舊的WS 10版本(我使用WS 11只是因為它應該與WebPack很好地配合使用)

WebStorm 11主要支持Webpack源映射,但您需要在Javascript Debug Run配置中相應地設置遠程URL映射,以便讓WebStorm知道帶有Webpack輸出文件的目錄(包括源映射)以及如何指定源文件的路徑sourcemap映射到項目中的位置。 因此,您需要指定已編譯的腳本Web服務器URL到其本地路徑的映射,並將源URL(在源映射中列出)映射到項目中的本地路徑。 聽起來很奇怪,但並不復雜。 對於像您這樣的配置文件,您可能必須指定遠程URL http://localhost:63342/webpack/Built用於捆綁文件和源映射所在的'Built'目錄,以及webpack:///. - 對於'js'目錄。 這對我來說很好......我們計划很快發布一篇關於webpack調試的博客文章......現在,我可以建議查看https://github.com/prigara/debugging-webpack這個簡單的例子

我絞盡腦汁待了幾個小時,我希望它可以幫助別人。 這篇博客文章中的說明實際上有效: https//blog.jetbrains.com/webstorm/2015/09/debugging-webpack-applications-in-webstorm/

因此,按照說明配置您的webstorm實例,但不要使用webpack-dev-server運行它,使用不同的Web服務器,如Ruby mine / rails中使用的WEBrick :: HTTPServer或內置調試服務器。 由於某種原因,webpack-dev-server沒有將源映射正確地與行號相關聯。

我想補充一點,你可以把聲明

調試器;

在你的javascript / typescript中甚至在angular或vue2的框架文件中。

因此,即使您的路徑映射到URL不起作用,它仍然會步進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM