热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

配置webpack以允许浏览器调试-Configurewebpacktoallowbrowserdebugging

IamnewtowebpackandIamconvertinganexistingwebapplicationtouseit.我是webpack的新手,我正在转换现有的

I am new to webpack and I am converting an existing web application to use it.

我是webpack的新手,我正在转换现有的Web应用程序来使用它。

I am using webpack to bundle and minify my JS which is great when deployed, however this makes it very challenging to debug while in developement.

我正在使用webpack捆绑和缩小我的JS,这在部署时非常好,但这使得在开发过程中进行调试非常具有挑战性。

Typically I use chrome's built in debugger to debug JS issues. (Or Firebug on firefox). However with webpack everything is stuffed in one file and it becomes challenging to debug using that mechanism.

通常我使用chrome的内置调试器来调试JS问题。 (或firefox上的Firebug)。然而,对于webpack,所有内容都填充在一个文件中,使用该机制进行调试变得具有挑战性。

Is there a way to quickly turn on and off bundeling? or turn on and off minifying?

有没有办法快速打开和关闭bundeling?或者打开和关闭缩小?

I have looked to see if there is some script loader configuration or other setting but it does not appear ovious.

我已经查看是否有一些脚本加载程序配置或其他设置,但它看起来不是很明显。

I have not yet had the time to convert everything to act like a module and use requires. So I simply use require("script!./file.js") pattern for my loading.

我还没有时间将所有内容转换为模块和使用要求。所以我只需要使用require(“script!。/ file.js”)模式进行加载。

5 个解决方案

#1


66  

You can use source maps to preserve the mapping between your source code and the bundled/minified one.

您可以使用源映射来保留源代码与捆绑/缩小的源代码之间的映射。

Webpack provides the devtool option to enhance debugging in the developer tool just creating a source map of the bundled file for you. This option can be used from the command line or used in your webpack.config.js configuration file.

Webpack提供了devtool选项,可以在开发人员工具中增强调试功能,只需为您创建捆绑文件的源映射。可以从命令行使用此选项,也可以在webpack.config.js配置文件中使用此选项。

Below you can find a contrived example using the command line to generate the bundled file (bundle.js) along with the generated source map file (bundle.js.map).

下面你可以找到一个人为的例子,使用命令行生成捆绑文件(bundle.js)以及生成的源映射文件(bundle.js.map)。

$ webpack --devtool source-map ./entry.js bundle.js
Hash: b13b8d9e3292806f8563
Version: webpack 1.12.2
Time: 90ms
        Asset     Size  Chunks             Chunk Names
    bundle.js  1.74 kB       0  [emitted]  main
bundle.js.map  1.89 kB       0  [emitted]  main
   [0] ./entry.js 85 bytes {0} [built]
   [1] ./hello.js 59 bytes {0} [built]

index.html


  
    
  
  
    
  

entry.js

var hello = require('./hello.js');
document.body.innerHTML += 'It works ' + hello();

hello.js

module.exports = function () {
  return 'Hello world!';
};

If you open index.html in your browser (I use Chrome but I think it is also supported in other browsers), you will see in the tab Sources that you have the bundled file under the file:// scheme and the source files under the special webpack:// scheme.

如果您在浏览器中打开index.html(我使用Chrome但我认为其他浏览器也支持它),您会在标签Source中看到您拥有file:// scheme下的捆绑文件和源文件特殊的webpack://方案。

debug with source maps

And yes, you can start debugging as if you had the original source code! Try to put a breakpoint in one line and refresh the page.

是的,您可以开始调试,就像您拥有原始源代码一样!尝试将断点放在一行中并刷新页面。

breakpoint with source maps

#2


2  

Source maps are very useful as already pointed out.
But sometimes selecting which source map to use could be a pain.

如前所述,源地图非常有用。但有时选择使用哪个源地图可能会很痛苦。

This comment on one of the Webpack source map issue might be helpful for selecting which source map to use based on requirements.

对Webpack源映射问题之一的这一评论可能有助于根据需求选择要使用的源映射。

#3


1  

Have a look Here

看看这里

its a beautifier that deminifies Javascript. at the bottom, it has a list of various plugins and extensions for browsers, check them out.

它是一个美化你的Javascript。在底部,它有一个浏览器的各种插件和扩展的列表,检查出来。

you might be interested in FireFox Deminifier , its supposed to deminify and style your Javascript when its retrieved from the server.

您可能对FireFox Deminifier感兴趣,它应该在从服务器检索时对您的Javascript进行细分和设置样式。

enter image description here

#4


1  

I recommend to debug in VsCode if you're in development.

如果您正在开发中,我建议您在VsCode中进行调试。

Debug experience is very good and all mapped correctly.

调试体验非常好,并且所有映射都正确。

enter image description here

You can follow this post to test.

你可以按照这篇文章进行测试。

#5


0  

I think its better to setup your project using production and development mode https://webpack.js.org/guides/production/ Its also include how to map your code to debug

我认为使用生产和开发模式更好地设置项目https://webpack.js.org/guides/production/它还包括如何将代码映射到调试

devtool: 'inline-source-map'

devtool:'inline-source-map'


推荐阅读
  • 本文记录了在vue cli 3.x中移除console的一些采坑经验,通过使用uglifyjs-webpack-plugin插件,在vue.config.js中进行相关配置,包括设置minimizer、UglifyJsPlugin和compress等参数,最终成功移除了console。同时,还包括了一些可能出现的报错情况和解决方法。 ... [详细]
  • JavaScript与DOM(上)——也适用于新手 – 深入理解JavaScript系列 23
    本文是《JavaScript深度解析》系列文章第23篇(共51篇)文档对象模 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • ItriedtouseFirebugLite(viathebookmarkletandalsoaddingittooneofmywebsites).我尝试使用Fi ... [详细]
  • 前端图片合成技术_靠谱的前端需要做哪些准备?
    Web前端开发源于传统的互联网,互联网普及让人才需求量居高不下,随着移动互联网的高速发展,移动终端的前端开发也越来越受到重视, ... [详细]
  • fiddler_Fiddler的原理和基本介绍
    一,Fiddler的工作原理   1,Fiddler是位于客户端和服务器端的HTTP ... [详细]
  • 一、选择器性能优化建议1.总是从#id选择器来继承这是jQuery选择器的一条黄金法则。jQuery选择一个元素最快的方法就是用ID来选择了。1$(#content).hide() ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • Java实战之电影在线观看系统的实现
    本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 从U ... [详细]
author-avatar
手机用户2502941301
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有