问题
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