@@ -60,17 +60,26 @@ export async function build(serverEntry?: string) {
60
60
moduleLoaders . length > 0 &&
61
61
`import { globToRegExp } from "https://deno.land/[email protected] /path/mod.ts";const moduleLoaders = []; globalThis["__ALEPH_MODULE_LOADERS"] = moduleLoaders;` ,
62
62
moduleLoaders . length > 0 &&
63
- moduleLoaders . map ( ( { meta } , idx ) => `
64
- import loader_${ idx } from ${ JSON . stringify ( meta . src ) } ;
65
- const reg = globToRegExp(${ JSON . stringify ( meta . glob ) } );
66
- moduleLoaders.push({
67
- meta: ${ JSON . stringify ( meta ) } ,
68
- test: (pathname) => {
69
- return reg.test(pathname) && loader_${ idx } .test(pathname);
70
- },
71
- load: (pathname, env) => loader_${ idx } .load(pathname, env),
72
- })
73
- ` ) . join ( "\n" ) ,
63
+ moduleLoaders . map ( ( loader , idx ) => {
64
+ const meta = Reflect . get ( loader , "meta" ) ;
65
+ return `
66
+ import loader$${ idx } from ${ JSON . stringify ( meta . src ) } ;
67
+ {
68
+ const reg = globToRegExp(${ JSON . stringify ( meta . glob ) } );
69
+ let loader = loader$${ idx } ;
70
+ if (typeof loader === "function") {
71
+ loader = new loader();
72
+ }
73
+ moduleLoaders.push({
74
+ meta: ${ JSON . stringify ( meta ) } ,
75
+ test: (pathname) => {
76
+ return reg.test(pathname) && loader.test(pathname);
77
+ },
78
+ load: (pathname, env) => loader.load(pathname, env),
79
+ })
80
+ }
81
+ ` ;
82
+ } ) . join ( "\n" ) ,
74
83
...routeFiles . map ( ( [ filename , exportNames ] , idx ) => {
75
84
const hasDefaultExport = exportNames . includes ( "default" ) ;
76
85
const hasDataExport = exportNames . includes ( "data" ) ;
@@ -145,8 +154,13 @@ export async function build(serverEntry?: string) {
145
154
name : "aleph-esbuild-plugin" ,
146
155
setup ( build ) {
147
156
build . onResolve ( { filter : / .* / } , ( args ) => {
148
- const isRemote = util . isLikelyHttpURL ( args . path ) ;
149
- const [ path ] = util . splitBy ( isRemote ? args . path : util . trimPrefix ( args . path , "file://" ) , "#" ) ;
157
+ let importUrl = args . path ;
158
+ if ( importUrl in importMap . imports ) {
159
+ importUrl = importMap . imports [ importUrl ] ;
160
+ }
161
+
162
+ const isRemote = util . isLikelyHttpURL ( importUrl ) ;
163
+ const [ path ] = util . splitBy ( isRemote ? importUrl : util . trimPrefix ( importUrl , "file://" ) , "#" ) ;
150
164
151
165
if ( args . kind === "dynamic-import" ) {
152
166
return { path, external : true } ;
0 commit comments