Deno:您可以拦截模块加载/导入吗? [英] Deno: Can you Intercept Module Loading/Importing?

查看:117
本文介绍了Deno:您可以拦截模块加载/导入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

deno 是否具有允许您拦截通过import包含的模块的加载的功能?

也就是说-在Node.js中,程序员可以定义需求以进行拦截CommonJS模块的加载. Node.js还具有实验加载器,可让您拦截ES6模块的加载.

deno是否有与其库存模块装载器(即import)类似的东西?如果不是,是否有计划在deno中进行类似的计划,或者该项目的哲学是否反对这种事情?

解决方案

默认情况下,CommonJS模块系统在DENO中不可用.但是,如果要拦截加载Node.js方式的模块,则必须在DENO中使用带有createRequire的npm模块.有关更多详细信息,请选中此答案如何在DENO中使用npm模块?

Does deno have any features that allow you to intercept the loading of a module that's included via import?

That is -- in Node.js programmers can redefine the require in order to intercept the loading of CommonJS modules. Node.js also features experimental loaders that allow you to intercept ES6 module loading.

Does deno have anything similar to this for its stock module loader (i.e. for import )? If not, are there plans for anything like this in deno, or does the project's philosophy stand opposed to this sort of thing?

解决方案

By default, CommonJS module system is not usable in DENO. However, if you want to intercept the modules loading the Node.js way, you have to use npm modules using createRequire in DENO. For more details Check this answer for How to use npm module in DENO?

这篇关于Deno:您可以拦截模块加载/导入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆