简体   繁体   中英

Is it possible to use whitelist in browser version of babel?

I wanted to use react in one of my university projects. Its not allowed to install anything, so I had to use browser version of react. It works fine but I wanted to use JSX in browser . It works fine with one file but if there are any import statements they get transpiled to require() calls which are obviously not supported in browsers.

So the question is: can I whitelist JSX or blacklist module transpiling here:

<script src="https://unpkg.com/babel-standalone@6/babel.js"></script>
<script src="/js/main.js" data-plugins="transform-react-jsx" type="text/babel"></script>

If its URL's are blocked, that's an issue you need to take up with your network administrator. If you want to support require statements in the browser, I'd look into something like browserify , RequireJS or another module loader.

Good solution: https://glitch.com/edit/#!/example-es-modules-with-babel
It requires to import every js file in.html, but its better than any other alternative that I've found

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM