简体   繁体   English

在 Javascript 控制台中使用所有应用程序的导入?

[英]Use All of App's Imports in Javascript Console?

When I'm in debug console for JS (during debug of a given source file), and I try to use a module that was imported in my source file, I get the following error:当我在 JS 的调试控制台中(在调试给定源文件期间),并且我尝试使用在我的源文件中导入的模块时,我收到以下错误:

Uncaught ReferenceError: myModule is not defined

It seems this will work for importing javascript modules for use in debugging console:这似乎适用于导入用于调试控制台的 javascript 模块:

import myModule from '/path/to/module.js';
window.myModule = myModule;

// in the console:
myModule.foo();

(See this answer for more details...) (有关更多详细信息,请参阅此答案...)

I want to be able to do this for all of the module imports in a given file, is this easily possible?我希望能够对给定文件中的所有模块导入执行此操作,这很容易吗?

Psuedo-code:伪代码:

for (i = 0; i < num_modules; i++) {
  window[module.name] = modules[i];
}

I don't believe there is a way to do what you are asking using static ES6 module imports.我不相信有一种方法可以使用静态 ES6 模块导入来完成您的要求。 You could probably create your own method for performing imports by making use of dynamic imports that could then attach the imported modules to the window , or else use a module loader/bundler that allows you to hook into the import process or otherwise exposes the list of imports.您可能可以通过使用动态导入创建自己的方法来执行导入,然后可以将导入的模块附加到window ,或者使用模块加载器/捆绑器,允许您挂接到导入过程或以其他方式公开列表进口。

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

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