Modules exported using es6 syntax for the browser

雨燕双飞 提交于 2020-01-04 13:44:23

问题


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.

来源:https://stackoverflow.com/questions/35403131/modules-exported-using-es6-syntax-for-the-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!