Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 4bf728c

Browse files
committed
Fix build
1 parent a2781ff commit 4bf728c

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

server/build.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

server/serve_dist.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ export default {
1616
try {
1717
let filePath = `./${outputDir}${pathname}`;
1818
let ctype = "application/javascript; charset=utf-8";
19-
if (searchParams.has("module") || pathname.startsWith("/-/esm.sh/")) {
20-
filePath += `.js`;
19+
if (
20+
searchParams.has("module") ||
21+
(pathname.startsWith("/-/esm.sh/") && !pathname.endsWith(".js") && !pathname.endsWith(".css"))
22+
) {
23+
filePath += ".js";
2124
}
2225
if (pathname.endsWith(".css") && !searchParams.has("module")) {
2326
ctype = "text/css; charset=utf-8";

server/transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default {
117117
...jsxConfig,
118118
lang: lang as TransformOptions["lang"],
119119
stripDataExport: isRouteFile(specifier),
120-
target: buildTarget ?? (isDev ? "es2022" : "es2015"),
120+
target: buildTarget ?? (isDev ? "es2022" : "es2020"),
121121
alephPkgUri,
122122
importMap: JSON.stringify(importMap),
123123
graphVersions,

server/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type BuildOptions = {
1818
platform?: BuildPlatform;
1919
/** The directory for build output files. default is "dist" */
2020
outputDir?: string;
21-
/** The build target passes to esbuild. */
21+
/** The build target passes to esbuild. default is "es2020" */
2222
target?: "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022";
2323
};
2424

0 commit comments

Comments
 (0)