Modules exported using es6 syntax for the browser

2019-07-11 09:30发布

问题:

I have a module module-A which has the following in index.js

import SomeModule from './lib/some-module'
import AnotherModule from './lib/another-module'

module.exports ={
 SomeModule: SomeModule, 
 AnotherModule: AnotherModule
}

I then use this module-A from another module-B:

import SomeModule from `module-A`

I now want to build module-B for the browser, so I use browserify from the module-B cwd: [I am using babel 6.0]

browserify index.js -t [ babelify  --presets [ es2015  ] ]

This throws an error as

import SomeModule from './lib/some-module'
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Is there anyway I can export modules using es6 export and import syntax and yet build properly for the browser.