简体   繁体   English

ES6模块加载器来解析符号引用

[英]ES6 Module loader to resolve symbolic references

We are trying to create an ES6 loader to use symbolic references to modules instead of well formed URIs or paths in import sentences. 我们正在尝试创建一个ES6加载器,以使用对模块的符号引用,而不是使用格式正确的URI或导入语句中的路径。 For instances, an import like this one: 例如,这样的导入:

import { foo } from 'com.bussines.platform.utils';

should be resolve the symbolic reference com.bussines.platform.utils to a real uri and proceed with the regular loading process to get foo . 应该将符号引用com.bussines.platform.utils为一个真正的uri,并继续进行常规加载过程以获取foo

To achieve this goal we are using the es-module-loader polyfill developed by @guybedford. 为了实现我们所使用的这个目标es-module-loader 填充工具通过@guybedford开发。 As, we are in the browser context, we have create a loader delegating to BrowserESModuleLoader : 因为我们在浏览器上下文中,所以我们创建了一个委托给BrowserESModuleLoader的加载器:

class CustomBrowserLoader extends RegisterLoader {

  constructor(Loader) {
    super();
    this.loader = new BrowserESModuleLoader();
  }

  [RegisterLoader.resolve] (key) {
    let uri = Resolve (key)
    return this.loader[RegisterLoader.resolve] (uri); // (1)
  }

  [RegisterLoader.instantiate] (uri) {
    return this.loader[RegisterLoader.instantiate] (uri); // (2)
  }
}

The problem is that, surprisingly, calls at lines (1) and (2) doesn't find the required methods resolve and instantiate . 问题在于,令人惊讶的是,在第(1)和(2)行的调用未找到所需的方法resolveinstantiate We have tried other approaches based on inheritance but getting similar results. 我们尝试了基于继承的其他方法,但是得到了相似的结果。

¿Could anyone give some insights about how to solve the problem? ¿任何人都可以提供有关如何解决问题的见解吗? Thanks in advance. 提前致谢。

Loaders are separate builds, so I think you would want BrowserESModuleLoader.resolve and BrowserESModuleLoader.instantiate here. 加载程序是单独的版本,因此我认为您希望将BrowserESModuleLoader.resolve和BrowserESModuleLoader.instantiate在这里。

It may be better though to directly fork the Browser ES Module Loader code itself, and adapt it to handle these types of specifiers directly instead. 最好直接分支浏览器ES Module Loader代码本身,并改编它直接处理这些类型的说明符。

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

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