简体   繁体   English

Chrome Javascript Sources转换导入模块名称

[英]Chrome Javascript Sources converting import module name

In my original source code, I have 在我的原始源代码中,

import myconst from '../utils/constants';
case myconst.XYZ:

However, in the Chrome Javascript source, I see the same converted as 但是,在Chrome Javascript源中,我看到了与

case _myAppUtilsConstants['default'].XYZ:

It also says define(...) for the imported module 它还为导入的模块显示define(...)

Is there some setting to prevent this conversion ? 是否有一些设置可以阻止这种转换?

Browsers don't currently support ES2016, so you use transpilers like Babel to convert ES2016 code into ES5 code. 浏览器目前不支持ES2016,让你用transpilers像巴贝尔到ES2016代码转换成ES5代码。 What you're seeing in Chrome is the generated ES5 code. 您在Chrome中看到的是生成的ES5代码。

You can use source maps to tell Chrome how your original code relates to the code that runs inside Chrome. 您可以使用源地图来告诉Chrome您的原始代码与Chrome中运行的代码之间的关系。

For example, Babel has a sourceMaps option and Webpack can also generate a source map . 例如,Babel有一个sourceMaps选项 ,Webpack也可以生成一个源地图

How this works specifically depends on the setup you are using to transpile your ES6 code. 具体如何工作取决于您用于转换ES6代码的设置。

You may have to enable source maps in Chrome first. 您可能必须先在Chrome中启用源地图

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM