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

Commit 5210023

Browse files
committed
Enhance compilation seepd
1 parent fe1920b commit 5210023

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

bundler/mod.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -136,58 +136,61 @@ export class Bundler {
136136
}
137137

138138
const bundlingFile = util.trimSuffix(mod.jsFile, '.js') + '.bundling.js'
139-
139+
this.#compiled.set(mod.url, bundlingFile)!
140140
if (existsFileSync(bundlingFile)) {
141141
return bundlingFile
142142
}
143143

144144
const source = await this.#app.readModule(mod.url)
145145
if (source === null) {
146+
this.#compiled.delete(mod.url)!
146147
throw new Error(`Unsupported module '${mod.url}'`)
147148
}
148149

149-
let { code, starExports } = await transform(
150-
mod.url,
151-
source.code,
152-
{
153-
...this.#app.sharedCompileOptions,
154-
swcOptions: {
155-
sourceType: source.type,
156-
},
157-
bundleMode: true,
158-
bundleExternal: external,
159-
}
160-
)
161-
162-
if (starExports && starExports.length > 0) {
163-
for (let index = 0; index < starExports.length; index++) {
164-
const url = starExports[index]
165-
const names = await this.#app.parseModuleExportNames(url)
166-
code = code.replace(`export * from "[${url}]:`, `export {${names.filter(name => name !== 'default').join(',')}} from "`)
167-
code = code.replace(`export const $$star_${index}`, `export const {${names.filter(name => name !== 'default').join(',')}}`)
168-
}
169-
}
170-
171-
this.#compiled.set(mod.url, bundlingFile)!
150+
try {
151+
let { code, starExports } = await transform(
152+
mod.url,
153+
source.code,
154+
{
155+
...this.#app.sharedCompileOptions,
156+
swcOptions: {
157+
sourceType: source.type,
158+
},
159+
bundleMode: true,
160+
bundleExternal: external,
161+
}
162+
)
172163

173-
// compile deps
174-
for (const dep of mod.deps) {
175-
if (!dep.url.startsWith('#') && !external.includes(dep.url)) {
176-
const depMod = this.#app.getModule(dep.url)
177-
if (depMod !== null) {
178-
await this.compile(depMod, external)
164+
if (starExports && starExports.length > 0) {
165+
for (let index = 0; index < starExports.length; index++) {
166+
const url = starExports[index]
167+
const names = await this.#app.parseModuleExportNames(url)
168+
code = code.replace(`export * from "[${url}]:`, `export {${names.filter(name => name !== 'default').join(',')}} from "`)
169+
code = code.replace(`export const $$star_${index}`, `export const {${names.filter(name => name !== 'default').join(',')}}`)
179170
}
180171
}
181-
}
182172

183-
await ensureTextFile(bundlingFile, code)
173+
// compile deps
174+
await Promise.all(mod.deps.map(async dep => {
175+
if (!dep.url.startsWith('#') && !external.includes(dep.url)) {
176+
const depMod = this.#app.getModule(dep.url)
177+
if (depMod !== null) {
178+
await this.compile(depMod, external)
179+
}
180+
}
181+
}))
184182

185-
return bundlingFile
183+
await ensureTextFile(bundlingFile, code)
184+
return bundlingFile
185+
} catch (e) {
186+
this.#compiled.delete(mod.url)!
187+
throw new Error(`Can't compile module '${mod.url}': ${e.message}`)
188+
}
186189
}
187190

188191
private async createMainJS() {
189192
const bundled = Array.from(this.#bundled.entries())
190-
.filter(([name]) => !['polyfill', 'deps', 'shared'].includes(name))
193+
.filter(([name]) => !['polyfills', 'deps', 'shared'].includes(name))
191194
.reduce((r, [name, filename]) => {
192195
r[name] = filename
193196
return r

server/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ export class Application implements ServerApplication {
731731

732732
return [
733733
simpleJSMinify(bundlerRuntimeCode),
734-
...['polyfill', 'deps', 'shared', 'main', entryFile ? util.trimSuffix(entryFile, '.js') : '']
734+
...['polyfills', 'deps', 'shared', 'main', entryFile ? util.trimSuffix(entryFile, '.js') : '']
735735
.filter(name => name !== "" && this.#bundler.getBundledFile(name) !== null)
736736
.map(name => ({
737737
src: `${basePath}/_aleph/${this.#bundler.getBundledFile(name)}`
@@ -1176,7 +1176,7 @@ export class Application implements ServerApplication {
11761176
}
11771177

11781178
// compile deps
1179-
for (const dep of mod.deps) {
1179+
await Promise.all(mod.deps.map(async dep => {
11801180
if (!dep.url.startsWith('#')) {
11811181
const depMod = await this.compile(dep.url, { once })
11821182
if (dep.hash === '' || dep.hash !== depMod.hash) {
@@ -1192,7 +1192,7 @@ export class Application implements ServerApplication {
11921192
}
11931193
}
11941194
}
1195-
}
1195+
}))
11961196

11971197
// update hash using deps status
11981198
if (mod.deps.length > 0) {

server/config.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Config, CSSOptions, PostCSSPlugin } from '../types.ts'
99
import { VERSION } from '../version.ts'
1010
import { getAlephPkgUri, reLocaleID } from './helper.ts'
1111

12-
export interface RequiredConfig extends Required<Config> {
12+
export type RequiredConfig = Required<Config> & {
1313
react: ReactResolve
1414
}
1515

@@ -25,10 +25,7 @@ export const defaultConfig: Readonly<RequiredConfig> = {
2525
rewrites: {},
2626
ssr: {},
2727
plugins: [],
28-
css: {
29-
modules: false,
30-
postcss: { plugins: ['autoprefixer'] },
31-
},
28+
css: {},
3229
headers: {},
3330
compress: true,
3431
env: {},

0 commit comments

Comments
 (0)