@@ -319,6 +319,8 @@ function createConfig(options, entry, format, writeMeta) {
319319 }
320320 loadNameCache ( ) ;
321321
322+ let shebang ;
323+
322324 let config = {
323325 inputOptions : {
324326 input : exportType ? resolve ( __dirname , '../src/lib/__entry__.js' ) : entry ,
@@ -375,14 +377,39 @@ function createConfig(options, entry, format, writeMeta) {
375377 babelrc : false ,
376378 exclude : 'node_modules/**' ,
377379 plugins : [
378- '@babel/plugin-syntax-jsx' ,
380+ require . resolve ( '@babel/plugin-syntax-jsx' ) ,
379381 [
380- 'babel-plugin-transform-async-to-promises' ,
382+ require . resolve ( 'babel-plugin-transform-async-to-promises' ) ,
381383 { inlineHelpers : true , externalHelpers : true } ,
382384 ] ,
383- [ '@babel/plugin-proposal-class-properties' , { loose : true } ] ,
385+ [
386+ require . resolve ( '@babel/plugin-proposal-class-properties' ) ,
387+ { loose : true } ,
388+ ] ,
384389 ] ,
385390 } ) ,
391+ {
392+ // Custom plugin that removes shebang from code because newer
393+ // versions of bublé bundle their own private version of `acorn`
394+ // and I don't know a way to patch in the option `allowHashBang`
395+ // to acorn.
396+ // See: https://github.com/Rich-Harris/buble/pull/165
397+ transform ( code ) {
398+ let reg = / ^ # ! ( .* ) / ;
399+ let match = code . match ( reg ) ;
400+
401+ if ( match !== null ) {
402+ shebang = '#!' + match [ 0 ] ;
403+ }
404+
405+ code = code . replace ( reg , '' ) ;
406+
407+ return {
408+ code,
409+ map : null ,
410+ } ;
411+ } ,
412+ } ,
386413 buble ( {
387414 exclude : 'node_modules/**' ,
388415 jsx : options . jsx || 'h' ,
@@ -459,7 +486,9 @@ function createConfig(options, entry, format, writeMeta) {
459486 config . _code = code ;
460487 } ,
461488 } ,
462- shebangPlugin ( ) ,
489+ shebangPlugin ( {
490+ shebang,
491+ } ) ,
463492 )
464493 . filter ( Boolean ) ,
465494 } ,
0 commit comments