Can I use Babel to compile JSX and export vars through the global namespace?
I don't want to run a random Webpack server.
I'm already wrapping my head around ES6, JSX, Babel, and React, and couldn't care less about another library that complicates such a simple task
Ultimately I would like to export my React class and import in another. Theoretically, it should only block until the dependencies are met, and I don't understand how this could be an anti-pattern, since all of my code and external dependencies are cached locally.
This is default behavior for <script>
tags, just not <script type="text/babel">
<script type="text/babel">
var message = "hello world";
</script>
<script type="text/babel">
console.log(message); // undefined
</script>
I'm fine with using ES6 export and import, but not another random file server
When (not) to use @babel/standalone. If you're using Babel in production, you should normally not use @babel/standalone. Instead, you should use a build system running on Node. js, such as Webpack, Rollup, or Parcel, to transpile your JS ahead of time.
It's time to fully embrace import/export With JavaScript modules fully supported in every major browser, savvy developers can now deliver production-ready apps without Webpack.
Webpack bundles our code and outputs a transpiled version down to the target as specified in the configuration file. In our webpack configuration file, module rules allow us to specify different loaders, which is an easy way to display loaders.
Babel can be classified as a tool in the "JavaScript Compilers" category, while Webpack is grouped under "JS Build Tools / JS Task Runners".
EDIT: Apparently export and import functionality was removed from Babel. I'm not sure why, but it has to do with ES6 compliance and possibly security?
Anyways, if you're determined to put them in separate files for dev purposes:
Put the class on a shared object (window)
SuperClass.js must be included 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 take Babel a while to transpile
It seems to work so far, will update if I find another solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With