@@ -340,7 +340,7 @@ either:
340
340
341
341
Loader code:
342
342
343
- ` ` ` js
343
+ ` ` ` mjs
344
344
// In the below example this file is referenced as
345
345
// '/path-to-my-loader.js'
346
346
@@ -352,7 +352,7 @@ export async function initialize({ number, port }) {
352
352
353
353
Caller code:
354
354
355
- ` ` ` js
355
+ ` ` ` mjs
356
356
import assert from ' node:assert' ;
357
357
import { register } from ' node:module' ;
358
358
import { MessageChannel } from ' node:worker_threads' ;
@@ -444,7 +444,7 @@ Node.js module specifier resolution behavior_ when calling `defaultResolve`, the
444
444
` context.conditions` array passed to it _must_ include _all_ elements of the
445
445
` context.conditions` array originally passed into the ` resolve` hook.
446
446
447
- ` ` ` js
447
+ ` ` ` mjs
448
448
export function resolve (specifier , context , nextResolve ) {
449
449
const { parentURL = null } = context;
450
450
@@ -544,7 +544,7 @@ loader in the `load` chain, returns `null` for `source` when `format` is
544
544
` ' commonjs' ` for backward compatibility. Here is an example loader that would
545
545
opt-in to using the non-default behavior:
546
546
547
- ` ` ` js
547
+ ` ` ` mjs
548
548
import { readFile } from ' node:fs/promises' ;
549
549
550
550
export async function load (url , context , nextLoad ) {
@@ -573,7 +573,7 @@ source code of an ES module specifier. This would allow a loader to potentially
573
573
avoid reading files from disk. It could also be used to map an unrecognized
574
574
format to a supported one, for example ` yaml` to ` module ` .
575
575
576
- ` ` ` js
576
+ ` ` ` mjs
577
577
export async function load (url , context , nextLoad ) {
578
578
const { format } = context;
579
579
@@ -632,7 +632,7 @@ builtins like "fs": `getBuiltin(request: string)`.
632
632
If the code needs more advanced ` require` features, it has to construct
633
633
its own ` require` using ` module .createRequire ()` .
634
634
635
- ` ` ` js
635
+ ` ` ` mjs
636
636
export function globalPreload (context ) {
637
637
return ` \
638
638
globalThis.someInjectedProperty = 42;
@@ -654,7 +654,7 @@ Some care must be taken in order to properly call [`port.ref()`][] and
654
654
[` port .unref ()` ][] to prevent a process from being in a state where it won't
655
655
close normally.
656
656
657
- ` ` ` js
657
+ ` ` ` mjs
658
658
/**
659
659
* This example has the application context send a message to the loader
660
660
* and sends the message back to the application context
@@ -688,7 +688,7 @@ functionality, there are substantial downsides to actually using this loader:
688
688
performance is much slower than loading files from disk, there is no caching,
689
689
and there is no security.
690
690
691
- ` ` ` js
691
+ ` ` ` mjs
692
692
// https-loader.mjs
693
693
import { get } from 'node:https';
694
694
@@ -717,7 +717,7 @@ export function load(url, context, nextLoad) {
717
717
}
718
718
` ` `
719
719
720
- ` ` ` js
720
+ ` ` ` mjs
721
721
// main.mjs
722
722
import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffeescript.js';
723
723
@@ -738,7 +738,7 @@ This is less performant than transpiling source files before running
738
738
Node.js; a transpiler loader should only be used for development and testing
739
739
purposes.
740
740
741
- ```js
741
+ ```mjs
742
742
// coffeescript-loader.mjs
743
743
import { readFile } from ' node: fs/ promises' ;
744
744
import { dirname, extname, resolve as resolvePath } from ' node: path' ;
@@ -848,7 +848,7 @@ that does its work via the `resolve` hook. This loader reads an
848
848
URL (this is a very simplistic implemenation of a small subset of the
849
849
"import maps" specification).
850
850
851
- ` ` ` js
851
+ ` ` ` mjs
852
852
// import-map-loader.js
853
853
import fs from ' node:fs/promises' ;
854
854
@@ -865,7 +865,7 @@ export async function resolve(specifier, context, nextResolve) {
865
865
866
866
Let's assume we have these files:
867
867
868
- ` ` ` js
868
+ ` ` ` mjs
869
869
// main.js
870
870
import ' a-module' ;
871
871
` ` `
@@ -879,7 +879,7 @@ import 'a-module';
879
879
}
880
880
` ` `
881
881
882
- ` ` ` js
882
+ ` ` ` mjs
883
883
// some-module.js
884
884
console .log (' some module!' );
885
885
` ` `
0 commit comments