简体   繁体   中英

Is it possible to run Babel without a cdn and Node?

I want to use Babel, to be able to support some IE browsers in my web-application. I previously used Node and some cdn's in my project, but replaced it with local min.js files, and i want to keep it this way if possible.

So far i have downloaded the babel.min.js, and replaced this:

<script src="./src/index.js"></script>

With this:

<script src="./src/index.js" type="text/babel"></script>

This threw CORS errors in Chrome and Firefox, and it's still just showing a blank page in IE. When testing i'm just running the files locally, so this might not be an issue when deploying to the server, but that's not possible right now.

I was reading a bit about the config files, and the closest i got was that i might need to create a .babelrc file. But the documentation keeps mentioning using NPM and the package.json file, which i want to avoid.

So right now i can't seem to figure out if what i'm trying to achieve is even possible. If possible, i'm uncertain as to how to tell Babel which file to transpile.

The errors thrown are:

Access to XMLHttpRequest at 'file:///C:/src/index.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

and

GET file:///C://src/index.js net::ERR_FAILED Blockquote

enter code here

Running it all through a local server seemed to fix it, and made Babel work. So i guess it is possible, and i didn't need to create a config file.

For anyone curious as to how i did it, i used this guide: How do you set up a local testing server?

I will off course need to test if the performance can handle transpiling it on the go. Otherwise i will have to transpile it before deploying it to the webserver, like Jed mentioned.

So as I understand you want to use Babel purely in the browser? Maybe @babel/standalone is the package you're looking for?

https://babeljs.io/docs/en/babel-standalone

I'm guessing you have your own good reasons for wanting to do it this way, but just in case a word of caution: Babel is first and foremost designed to be used to process your code on the command line before you deploy it to a webserver.

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