Browserify import/require?

◇◆丶佛笑我妖孽 提交于 2019-12-18 12:16:23

问题


I'm trying to pick up browserify and have been through a number of examples.

In one example I see the use of 'import':

import 'jquery';

and importing local files with:

import Header from './Header';

but in other examples I see people importing via:

require('./Header');

What is the difference?


回答1:


require() is the Node module system (CommonJS) in ES5. import is ES6 module syntax.

If you want to browserify modules written with ES6 module syntax you'll need to compile them using something like babelify (or babel by other means).



来源:https://stackoverflow.com/questions/33042867/browserify-import-require

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