Skip to content

Commit

Permalink
add es module entry into package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Mar 20, 2018
1 parent ca62475 commit 6b7ab33
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions build/build.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ namespace $ {
var envsDef = [ 'web' , 'node' ]
var envs = bundle ? [] as string[] : envsDef.slice()
var stages = [ 'test' , 'dev' ]

var moduleTargets = ['', 'esm']
if( bundle ) {

var [ bundle , tags , type , locale ] = /^(.*?)(?:\.(test\.js|test\.html|js|css|deps\.json|locale=(\w+)\.json))?$/.exec(
Expand All @@ -462,7 +462,11 @@ namespace $ {
res = res.concat( this.bundleCSS( { path , exclude , bundle : env } ) )
}
if( !type || type === 'js' ) {
res = res.concat( this.bundleJS( { path , exclude , bundle : env } ) )
moduleTargets.forEach(
moduleTarget => {
res = res.concat( this.bundleJS( { path , exclude , bundle : env, moduleTarget } ) )
}
)
}
if( !type || type === 'test.js' ) {
res = res.concat( this.bundleTestJS( { path , exclude , bundle : env } ) )
Expand Down Expand Up @@ -508,11 +512,11 @@ namespace $ {
}

@ $mol_mem_key
bundleJS( { path , exclude , bundle } : { path : string , exclude? : string[] , bundle : string } ) : $mol_file[] {
bundleJS( { path , exclude , bundle , moduleTarget } : { path : string , exclude? : string[] , bundle : string, moduleTarget? : string } ) : $mol_file[] {
var pack = $mol_file.absolute( path )

var target = pack.resolve( `-/${bundle}.js` )
var targetMap = pack.resolve( `-/${bundle}.js.map` )
var mt = moduleTarget ? `.${moduleTarget}` : ''
var target = pack.resolve( `-/${bundle}${mt}.js` )
var targetMap = pack.resolve( `-/${bundle}${mt}.js.map` )

var sources = this.sourcesJS( { path , exclude } )
if( sources.length === 0 ) return []
Expand Down Expand Up @@ -553,7 +557,9 @@ namespace $ {
}
}
)

if( moduleTarget === 'esm' ) {
concater.add( '-', 'export default $')
}
target.content( concater.content + '\n//# sourceMappingURL=' + targetMap.relate( target.parent() ) )
targetMap.content( concater.sourceMap )

Expand Down Expand Up @@ -688,11 +694,12 @@ namespace $ {
var targetMap = pack.resolve( `-/package.json` )

var sources = this.sourcesAll( { path , exclude : exclude.filter( ex => ex !== 'test' && ex !== 'dev' ) } )

var json = {
name : pack.relate( this.root() ).replace( /\//g , '_' ) ,
version : '0.0.0' ,
main : 'node.js' ,
module : 'web.esm.js',
browser : 'web.esm.js',
dependencies : <{ [ key : string ] : string }>{}
}

Expand Down

0 comments on commit 6b7ab33

Please sign in to comment.