Kuan
Kuan

Reputation: 11389

How to implement "import" syntax in ES6 in ES5

All:

I have never learnt ES6 before, but when I tried React Router, the guide is almost written in ES6, and there is a part using 'import A from b', after looking it up, it turns out that that is ES6 syntax, I wonder how can I implement this with ES5? Is this just a simplely using:

var A = require("b");

Thanks

Upvotes: 1

Views: 495

Answers (2)

Nathan
Nathan

Reputation: 31

Like others have been saying, you're going to want to use a transpiler for your code - and babel is what you're looking for.

Depending on the size of your project, implementing something like webpack will be very useful for compiling your project.

There's some great tutorials on building out an application with react, webpack, and babel. There's some great boilerplates out there too.

This medium post does an amazing job going through setting up an isomorphic/universal application with redux! https://medium.com/front-end-developers/handcrafting-an-isomorphic-redux-application-with-love-40ada4468af4#.x6h3b717u


now regarding your question - Yes. import's are just a simpler, nicer way of using require :)

Upvotes: 1

Robbie
Robbie

Reputation: 45

I find that babel works best for transpiling the code. It is the same as a require but the new import and export is more flexible. For easy use with react I would definitely look into jspm http://jspm.io/docs/index.html

Upvotes: 1

Related Questions