Closed stefek99 closed 6 years ago
I'm not sure how ES6 modules would work within the context of a browser - How would you define the module name, for example?
I'm sorry, not an expert here, and I know my case was pretty edgy...
I think I wanted to edit source file of some library and have it loaded directly into browser as I was working on limited environment (no admin rights, cannot install anything)
I also need to use exports defaults in my work completion university course, if you can find a solution I will be grateful if you share
I think if you have a jsFiddle, I may want to import external files. For example from rawgit.com
Native module loading is coming to browsers. In fact, it's already available in Firefox, Safari and Edge, but only in pre-release versions, and then hidden behind a flag. Here's a very good blog post that gives an overview of the current state of play: https://blog.hospodarets.com/native-ecmascript-modules-the-first-overview
I tested native module loading, using version 54 of the Firefox Nightly build with the dom.moduleScripts.enabled boolean flag set to true. This is bleeding edge stuff to be sure, but I can confirm that it does work!
It would be great if babel-standalone could somehow work together with native module loading to transpile React, for example.
How would one integrate the two though? One stumbling block is that native module loading requires that the initial script is loaded as<script type="module"
, whereas babel-standalone requires <script type="text/babel"
.
See also issue #71
What is the solution to get this to work?
test.html:
<!doctype html>
<html>
<head>
<title>Babel Test</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.14.0/babel.min.js"></script>
<script data-plugins="transform-es2015-modules-umd" type="text/babel" src="./cube.js"></script>
<script data-plugins="transform-es2015-modules-umd" type="text/babel">
import cube from 'cube'
console.log(cube(3))
</script>
</body>
</html>
cube.js
export default function cube(x) {
return x * x * x;
}
Is there a solution for this? Should we move this to the main Babel repo for more exposure (now that standalone has moved)?
I think https://github.com/babel/babel/pull/6223 should actually fix this.
If that PR doesn't fix it, let's open a new issue in the Babel repo 😃
https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export
I have following code:
I can export
function cube
but how do Iimport
it?Note that
data-plugins="transform-es2015-modules-umd"
is required, otherwise it will throwReferenceError: exports is not defined