Use Babel to forward, import, and export in a client without Webpack?

Can I use Babel to compile JSX and export vars through the global namespace?

I do not want to start a random webpack server.

I already embrace ES6, JSX, Babel and React, and I don't care about another library that complicates such a simple task

Ultimately, I would like to export the React class and import it into another. Theoretically, it should only be blocked until the dependencies are fulfilled, and I don’t understand how it can be an anti-pattern, since all my code and external dependencies are cached locally.

This is the default behavior for <script> tags, not <script type="text/babel">

 <script type="text/babel"> var message = "hello world"; </script> <script type="text/babel"> console.log(message); // undefined </script> 

I am fine using ES6 export and import, but not for another random file server

+7
javascript ecmascript-6 reactjs babeljs jsx
source share
1 answer

EDIT: Obviously, the export and import functions have been removed from Babel. I'm not sure why, but is it due to ES6 compliance and possibly security?

In any case, if you decide to put them in separate files for dev purposes:

Put the class in a shared object (window)

SuperClass.js must be enabled before SubClass.js

 class MySuperClass () { constructor (config) { super(config); } } window.MySuperClass = MySuperClass; 

 var MySuperClass = window.MySuperClass; class MySubClass extends MySuperClass () { constructor (config) { super(config); } } 

I'm not sure if this works for very large classes that force Babel to translate

It seems to be working so far, will be updated if I find another solution

+1
source share

All Articles