node-network-import-test
Node.jsでも、denoのようにhttps経由でESModulesをインポート出来るらしいのでテスト。
Scrapboxのコードブロックで書いたスクリプトを実行できそう。
https://nodejs.org/api/esm.html#https-and-http-imports
Https imports by bmeck · Pull Request #36328 · nodejs/node · GitHub
このコードをNode.jsで実行させる。
code: index.js
export const main = () => {
console.log("Hello!!");
};
ローカル環境に、ブートローダーのようなmjsファイルが必要。
code: node-network-import-test.mjs
import { main } from "https://scrapbox.io/api/code/hata6502/node-network-import-test/index.js";
main();
--experimental-network-importsフラグを付けて、Node.jsを実行する。
code: bash
$ node --experimental-network-imports node-network-import-test.mjs
(node:54622) ExperimentalWarning: Network Imports is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
Hello!!