@@ -34,7 +34,7 @@ export async function build(serverEntry?: string) {
3434 const moduleLoaders = await initModuleLoaders ( importMap ) ;
3535 const config : AlephConfig | undefined = Reflect . get ( globalThis , "__ALEPH_CONFIG" ) ;
3636 const platform = config ?. build ?. platform ?? "deno" ;
37- const target = config ?. build ?. target ?? "es2015 " ;
37+ const target = config ?. build ?. target ?? "es2020 " ;
3838 const outputDir = join ( workingDir , config ?. build ?. outputDir ?? "dist" ) ;
3939
4040 if ( platform === "cloudflare" || platform === "vercel" ) {
@@ -252,15 +252,15 @@ export async function build(serverEntry?: string) {
252252 const html = await Deno . readFile ( join ( workingDir , "index.html" ) ) ;
253253 const links = await parseHtmlLinks ( html ) ;
254254 for ( const src of links ) {
255- if ( ! util . isLikelyHttpURL ( src ) ) {
256- const ext = extname ( util . splitBy ( src , "?" ) [ 0 ] ) . slice ( 1 ) ;
257- if ( ext === "css" || builtinModuleExts . includes ( ext ) ) {
258- const specifier = "." + util . cleanPath ( src ) ;
259- tasks . push ( specifier ) ;
260- }
255+ const url = new URL ( src , "http://localhost/" ) ;
256+ const ext = extname ( url . pathname ) . slice ( 1 ) ;
257+ if ( ext === "css" || builtinModuleExts . includes ( ext ) ) {
258+ const specifier = util . isLikelyHttpURL ( src ) ? src : "." + util . cleanPath ( src ) ;
259+ tasks . push ( specifier ) ;
261260 }
262261 }
263262 }
263+ tasks . push ( `${ alephPkgUri } /framework/core/nomodule.ts` ) ;
264264
265265 const entryModules = new Set ( tasks ) ;
266266 const allModules = new Set < string > ( ) ;
@@ -275,7 +275,7 @@ export async function build(serverEntry?: string) {
275275 const isCSS = url . pathname . endsWith ( ".css" ) ;
276276 const req = new Request ( url . toString ( ) ) ;
277277 let savePath = join ( outputDir , url . pathname ) ;
278- if ( specifier . startsWith ( "https://esm.sh/" ) ) {
278+ if ( specifier . startsWith ( "https://esm.sh/" ) && ! specifier . endsWith ( ".js" ) && ! specifier . endsWith ( ".css" ) ) {
279279 savePath += ".js" ;
280280 } else if ( isCSS && url . searchParams . has ( "module" ) ) {
281281 savePath += ".js" ;
@@ -377,7 +377,7 @@ export async function build(serverEntry?: string) {
377377 if ( counter . size > 1 ) {
378378 clientModules . add ( specifier ) ;
379379 }
380- console . log ( `${ specifier } is referenced by \n - ${ Array . from ( counter ) . join ( "\n - " ) } ` ) ;
380+ // console.log(`[ ${specifier}] \n - ${Array.from(counter).join("\n - ")}`);
381381 } ) ;
382382
383383 // bundle client modules
@@ -394,7 +394,7 @@ export async function build(serverEntry?: string) {
394394 Array . from ( bundling ) . map ( async ( entryPoint ) => {
395395 const url = new URL ( util . isLikelyHttpURL ( entryPoint ) ? toLocalPath ( entryPoint ) : entryPoint , "http://localhost" ) ;
396396 let jsFile = join ( outputDir , url . pathname ) ;
397- if ( entryPoint . startsWith ( "https://esm.sh/" ) ) {
397+ if ( entryPoint . startsWith ( "https://esm.sh/" ) && ! entryPoint . endsWith ( ".js" ) && ! entryPoint . endsWith ( ".css" ) ) {
398398 jsFile += ".js" ;
399399 }
400400 await esbuild ( {
@@ -408,11 +408,19 @@ export async function build(serverEntry?: string) {
408408 minify : true ,
409409 treeShaking : true ,
410410 sourcemap : false ,
411+ loader : {
412+ ".vue" : "js" ,
413+ } ,
411414 plugins : [ {
412415 name : "aleph-esbuild-plugin" ,
413416 setup ( build ) {
414417 build . onResolve ( { filter : / .* / } , ( args ) => {
415- const path = util . trimPrefix ( args . path , outputDir ) ;
418+ let argsPath = args . path ;
419+ if ( argsPath . startsWith ( "./" ) || argsPath . startsWith ( "../" ) ) {
420+ argsPath = join ( args . resolveDir , argsPath ) ;
421+ }
422+ const [ fp , q ] = util . splitBy ( argsPath , "?" ) ;
423+ const path = util . trimPrefix ( fp , outputDir ) ;
416424 let specifier = "." + path ;
417425 if ( args . path . startsWith ( "/-/" ) ) {
418426 specifier = restoreUrl ( path ) ;
@@ -421,8 +429,14 @@ export async function build(serverEntry?: string) {
421429 return { path : args . path , external : true } ;
422430 }
423431 let jsFile = join ( outputDir , path ) ;
424- if ( specifier . startsWith ( "https://esm.sh/" ) ) {
432+ if (
433+ specifier . startsWith ( "https://esm.sh/" ) && ! specifier . endsWith ( ".js" ) && ! specifier . endsWith ( ".css" )
434+ ) {
425435 jsFile += ".js" ;
436+ } else {
437+ if ( specifier . endsWith ( ".css" ) && new URLSearchParams ( q ) . has ( "module" ) ) {
438+ jsFile += ".js" ;
439+ }
426440 }
427441 return { path : jsFile } ;
428442 } ) ;
0 commit comments