@@ -10,7 +10,7 @@ import { VERSION } from '../version.ts'
10
10
import { Request } from './api.ts'
11
11
import log from './log.ts'
12
12
import type { DependencyDescriptor , ImportMap , Module , RenderResult } from './types.ts'
13
- import { cleanupCompilation , colorfulBytesString , createHtml , ensureTextFile , existsDirSync , existsFileSync , fixImportMap , fixImportUrl , getAlephPkgUrl , getRelativePath , newModule } from './util.ts'
13
+ import { AlephRuntimeCode , cleanupCompilation , colorfulBytesString , createHtml , ensureTextFile , existsDirSync , existsFileSync , fixImportMap , fixImportUrl , getAlephPkgUrl , getRelativePath , newModule } from './util.ts'
14
14
15
15
/**
16
16
* A Project to manage the Aleph.js appliaction.
@@ -1262,28 +1262,6 @@ export class Project {
1262
1262
1263
1263
/** bundle modules for production. */
1264
1264
private async _bundle ( ) {
1265
- const header = `
1266
- var __ALEPH = window.__ALEPH || (window.__ALEPH = {
1267
- pack: {},
1268
- exportFrom: function(specifier, url, exports) {
1269
- if (url in this.pack) {
1270
- var mod = this.pack[url]
1271
- if (!(specifier in this.pack)) {
1272
- this.pack[specifier] = {}
1273
- }
1274
- if (exports === '*') {
1275
- for (var k in mod) {
1276
- this.pack[specifier][k] = mod[k]
1277
- }
1278
- } else if (typeof exports === 'object' && exports !== null) {
1279
- for (var k in exports) {
1280
- this.pack[specifier][exports[k]] = mod[k]
1281
- }
1282
- }
1283
- }
1284
- }
1285
- });
1286
- ` . replaceAll ( ' ' . repeat ( 12 ) , '' )
1287
1265
const alephPkgUrl = getAlephPkgUrl ( )
1288
1266
const refCounter = new Map < string , number > ( )
1289
1267
const lookup = ( url : string ) => {
@@ -1340,9 +1318,9 @@ export class Project {
1340
1318
}
1341
1319
1342
1320
log . info ( '- Bundle' )
1343
- await this . _createChunkBundle ( 'deps' , remoteDepList , header )
1321
+ await this . _createChunkBundle ( 'deps' , remoteDepList )
1344
1322
if ( localDepList . length > 0 ) {
1345
- await this . _createChunkBundle ( 'shared' , localDepList , header )
1323
+ await this . _createChunkBundle ( 'shared' , localDepList )
1346
1324
}
1347
1325
1348
1326
// copy main module
@@ -1353,17 +1331,17 @@ export class Project {
1353
1331
1354
1332
// create and copy polyfill
1355
1333
const polyfillMode = newModule ( '/polyfill.js' )
1356
- polyfillMode . hash = polyfillMode . sourceHash = ( new Sha1 ) . update ( header ) . update ( `${ this . config . buildTarget } -${ VERSION } ` ) . hex ( )
1334
+ polyfillMode . hash = polyfillMode . sourceHash = ( new Sha1 ) . update ( AlephRuntimeCode ) . update ( `${ this . config . buildTarget } -${ VERSION } ` ) . hex ( )
1357
1335
const polyfillFile = path . join ( this . buildDir , `polyfill.${ polyfillMode . hash . slice ( 0 , hashShort ) } .js` )
1358
1336
if ( ! existsFileSync ( polyfillFile ) ) {
1359
1337
const rawPolyfillFile = `${ alephPkgUrl } /compiler/polyfills/${ this . config . buildTarget } /polyfill.js`
1360
- await this . _runDenoBundle ( rawPolyfillFile , polyfillFile , header , true )
1338
+ await this . _runDenoBundle ( rawPolyfillFile , polyfillFile , AlephRuntimeCode , true )
1361
1339
}
1362
1340
Deno . copyFile ( polyfillFile , path . join ( this . outputDir , '_aleph' , `polyfill.${ polyfillMode . hash . slice ( 0 , hashShort ) } .js` ) )
1363
1341
this . #modules. set ( polyfillMode . url , polyfillMode )
1364
1342
1365
1343
// bundle and copy page moudles
1366
- await Promise . all ( pageModules . map ( async mod => this . _createPageBundle ( mod , localDepList , header ) ) )
1344
+ await Promise . all ( pageModules . map ( async mod => this . _createPageBundle ( mod , localDepList , AlephRuntimeCode ) ) )
1367
1345
}
1368
1346
1369
1347
/** create chunk bundle. */
@@ -1403,11 +1381,11 @@ export class Project {
1403
1381
1404
1382
/** create page bundle. */
1405
1383
private async _createPageBundle ( mod : Module , bundledPaths : string [ ] , header = '' ) {
1406
- const { bundlingFile, sourceHash } = await this . _compile ( mod . url , { bundleMode : true , bundledPaths } )
1384
+ const { bundlingFile, hash } = await this . _compile ( mod . url , { bundleMode : true , bundledPaths } )
1407
1385
const _tmp = util . trimSuffix ( bundlingFile . replace ( reHashJs , '' ) , '.bundling' )
1408
1386
const _tmp_bundlingFile = _tmp + `.bundling.js`
1409
- const bundleFile = _tmp + `.bundle.${ sourceHash . slice ( 0 , hashShort ) } .js`
1410
- const saveAs = path . join ( this . outputDir , `/_aleph/` , util . trimPrefix ( _tmp , this . buildDir ) + `.${ sourceHash . slice ( 0 , hashShort ) } .js` )
1387
+ const bundleFile = _tmp + `.bundle.${ hash . slice ( 0 , hashShort ) } .js`
1388
+ const saveAs = path . join ( this . outputDir , `/_aleph/` , util . trimPrefix ( _tmp , this . buildDir ) + `.${ hash . slice ( 0 , hashShort ) } .js` )
1411
1389
1412
1390
if ( existsFileSync ( bundleFile ) ) {
1413
1391
await ensureDir ( path . dirname ( saveAs ) )
0 commit comments