zoukankan      html  css  js  c++  java
  • graalvm 内置require 模块的开启

    实际上graalvm 包含了体验特性的require 支持(commonjs)

    配置说明

    Map<String, String> options = new HashMap<>();
    // Enable CommonJS experimental support.
    options.put("js.commonjs-require", "true");
    // (optional) folder where the NPM modules to be loaded are located.
    options.put("js.commonjs-require-cwd", "/path/to/root/folder");
    // (optional) initialization script to pre-define globals.
    options.put("js.commonjs-global-properties", "./globals.js");
    // (optional) Node.js built-in replacements as a comma separated list.
    options.put("js.commonjs-core-modules-replacements",
                "buffer:buffer/," +
                "path:path-browserify");
    // Create context with IO support and experimental options.
    Context cx = Context.newBuilder("js")
                                .allowExperimentalOptions(true)
                                .allowIO(true)
                                .options(options)
                                .build();
    // Require a module
    Value module = cx.eval("js", "require('some-module');");

    参考资料

    https://github.com/graalvm/graaljs/blob/master/docs/user/NodeJSVSJavaScriptContext.md

  • 相关阅读:
    javascript --学习this
    seaJS
    wamp之htaccess的配置
    replace之$1、$2等
    nw.js使用
    新电脑开发环境配置
    vue-vue常用指令
    Array的splice与slice
    vue-入门体验
    Object.defineProperty
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/13585073.html
Copyright © 2011-2022 走看看