-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel standalone type module #8410
Babel standalone type module #8410
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8737/ |
1 similar comment
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8737/ |
<pre id="output">Loading...</pre> | ||
|
||
<script src="../babel.js"></script> | ||
<script type="text/babel/module" data-presets='es2016'> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to do this, we should use a mimetype parameter like text/babel; goal=module
and ideally parse the type a bit rather than doing a general .indexOf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy with that. I used indexOf
because I saw it used here https://github.com/babel/babel/pull/8410/files#diff-7a71ff75920619cbc0e67883df263ca8L188. Is there anywhere in the codebase (or elsewhere) you can point me toward regard parsing something like the mimetype you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, yeah that at least does type.split(";")
so it's not as generic. I'd vote for
script.type.split(';').slice(1).some(meta => /^\s*type\s*=\s*module\s*$/.test(meta))
probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks! I will give it a go 👍
I just found this PR, any status updates? |
We added support for |
I have been building an in browser based dev environment that takes advantage of script
type="module"
with native staticimport
statements. Everything worked great until I tried building an app that uses JSX. For that to work in the browser it needs to be transpiled.I employed
@babel/standalone
to do this for me in the browser. It was at this point that I realised a conflict in script types; I needed<script type="text/babel">
to flag to babel standalone that the code was to be transpiled but also required<script type="module">
in order for native imports to work correctly.I searched the
babel-standalone
repo for similar issues and found this babel/babel-standalone#96. So I added this comment babel/babel-standalone#96 (comment) questioning wether use of thetype
attribute was required. Some others replied saying they had similar issues but we got no reply for any maintainers and the issue was subsequently archived a week or so later.So here is my suggestion but in working code. The changes are minimal but have the desired effect; if you mark a script with
type="text/jsx/module"
then babel standalone picks up that the script needs to be transpiled and addstype="module"
to the resultant script tag which gets appended to the head.Thanks for your time 🙇