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

Commit 15e4866

Browse files
committed
Update compile options
1 parent 2a69225 commit 15e4866

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

bundler/mod.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class Bundler {
7777
})
7878

7979
if (this.#app.config.buildTarget !== 'esnext') {
80-
await this.bundlePolyfillChunck()
80+
await this.bundlePolyfillsChunck()
8181
}
8282
await this.bundleChunk(
8383
'deps',
@@ -146,7 +146,6 @@ export class Bundler {
146146
{
147147
...this.#app.sharedCompileOptions,
148148
swcOptions: {
149-
target: 'es2020',
150149
sourceType: source.type,
151150
},
152151
bundleMode: true,
@@ -157,8 +156,8 @@ export class Bundler {
157156
if (starExports && starExports.length > 0) {
158157
for (let index = 0; index < starExports.length; index++) {
159158
const url = starExports[index]
160-
const source = await this.#app.resolveModule(url)
161-
const names = await parseExportNames(url, source.code, { sourceType: source.type })
159+
const names = await this.#app.parseModuleExportNames(url)
160+
code = code.replace(`export * from "[${url}]:`, `export {${names.filter(name => name !== 'default').join(',')}} from "`)
162161
code = code.replace(`export const $$star_${index}`, `export const {${names.filter(name => name !== 'default').join(',')}}`)
163162
}
164163
}
@@ -168,14 +167,7 @@ export class Bundler {
168167
if (!dep.url.startsWith('#') && !external.includes(dep.url)) {
169168
const depMod = this.#app.getModule(dep.url)
170169
if (depMod !== null) {
171-
const s = `.bundling.js#${dep.url}@`
172170
await this.compile(depMod, external)
173-
code = code.split(s).map((p, i) => {
174-
if (i > 0 && p.charAt(6) === '"') {
175-
return dep.hash.slice(0, 6) + p.slice(6)
176-
}
177-
return p
178-
}).join(s)
179171
}
180172
}
181173
}
@@ -201,20 +193,20 @@ export class Bundler {
201193
log.info(` {} main.js ${dim('• ' + util.formatBytes(mainJS.length))}`)
202194
}
203195

204-
/** create polyfill bundle. */
205-
private async bundlePolyfillChunck() {
196+
/** create polyfills bundle. */
197+
private async bundlePolyfillsChunck() {
206198
const alephPkgUri = getAlephPkgUri()
207199
const { buildTarget } = this.#app.config
208-
const polyfillTarget = 'es' + (parseInt(buildTarget.slice(2)) + 1)
200+
const polyfillTarget = 'es' + (parseInt(buildTarget.slice(2)) + 1) // buildTarget + 1
209201
const hash = computeHash(polyfillTarget + '/[email protected]/' + VERSION)
210-
const bundleFilename = `polyfill.bundle.${hash.slice(0, hashShort)}.js`
202+
const bundleFilename = `polyfills.bundle.${hash.slice(0, hashShort)}.js`
211203
const bundleFilePath = join(this.#app.buildDir, bundleFilename)
212204
if (!existsFileSync(bundleFilePath)) {
213-
const rawPolyfillFile = `${alephPkgUri}/bundler/polyfills/${polyfillTarget}/mod.ts`
214-
await this.build(rawPolyfillFile, bundleFilePath)
205+
const rawPolyfillsFile = `${alephPkgUri}/bundler/polyfills/${polyfillTarget}/mod.ts`
206+
await this.build(rawPolyfillsFile, bundleFilePath)
215207
}
216-
this.#bundledFiles.set('polyfill', bundleFilename)
217-
log.info(` {} polyfill.js (${buildTarget.toUpperCase()}) ${dim('• ' + util.formatBytes(Deno.statSync(bundleFilePath).size))}`)
208+
this.#bundledFiles.set('polyfills', bundleFilename)
209+
log.info(` {} polyfills.js (${buildTarget.toUpperCase()}) ${dim('• ' + util.formatBytes(Deno.statSync(bundleFilePath).size))}`)
218210
}
219211

220212
/** create bundle chunk. */

server/app.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,17 @@ export class Application implements ServerApplication {
10021002
}
10031003
}
10041004

1005+
async parseModuleExportNames(url: string): Promise<string[]> {
1006+
const source = await this.resolveModule(url)
1007+
const names = await parseExportNames(url, source.code, { sourceType: source.type })
1008+
return (await Promise.all(names.map(async name => {
1009+
if (name.startsWith('{') && name.startsWith('}')) {
1010+
return await this.parseModuleExportNames(name.slice(1, -1))
1011+
}
1012+
return name
1013+
}))).flat()
1014+
}
1015+
10051016
/** compile a moudle by given url, then cache on the disk. */
10061017
private async compile(
10071018
url: string,
@@ -1115,7 +1126,6 @@ export class Application implements ServerApplication {
11151126
...this.sharedCompileOptions,
11161127
sourceMap: this.isDev,
11171128
swcOptions: {
1118-
target: 'es2020',
11191129
sourceType: source.type
11201130
},
11211131
})
@@ -1125,13 +1135,12 @@ export class Application implements ServerApplication {
11251135
jsSourceMap = map
11261136
}
11271137

1128-
// in bundle mode we replace the star export with names
1138+
// in production/bundle mode we need to replace the star export with names
11291139
if (starExports && starExports.length > 0) {
11301140
for (let index = 0; index < starExports.length; index++) {
11311141
const url = starExports[index]
1132-
const source = await this.resolveModule(url)
1133-
const names = await parseExportNames(url, source.code, { sourceType: source.type })
1134-
jsContent = jsContent.replace(`export * from "${url}:`, `export {${names.filter(name => name !== 'default').join(',')}} from "`)
1142+
const names = await this.parseModuleExportNames(url)
1143+
jsContent = jsContent.replace(`export * from "[${url}]:`, `export {${names.filter(name => name !== 'default').join(',')}} from "`)
11351144
}
11361145
}
11371146

0 commit comments

Comments
 (0)