浏览导入/要求? [英] Browserify import/require?

查看:76
本文介绍了浏览导入/要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在一个例子中,我看到使用'import':

  import'jquery'; 

并导入本地文件:

 从'./Header'导入标头; 

但在其他示例中,我看到通过以下方式导入的人员:

  require('./ Header'); 

有什么区别?

解决方案

require()是ES5中的Node模块系统(CommonJS)。 import 是ES6模块语法。



如果要浏览使用ES6模块语法编写的模块,您需要编译他们使用像babelify(或通过其他方式babelify)。


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?

解决方案

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).

这篇关于浏览导入/要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆