javascriptnode.jsbabeljstranspiler

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


Solution

  • 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.