Sublime Forum

How to Use Babel Without Node.js

#1

I installed Babel with the package installer.
But i noticed the babel config file seems to be pointing to a non-existent node.js folder:

babel.sublime-settings:

{
  "debug": false,
  "use_local_babel": true,
  "node_modules": {
    "windows": "C:/Program Files/nodejs/node_modules",
    "linux": "/usr/lib/node_modules",
    "osx": "/usr/local/lib/node_modules"
  },
  "options": {}
}

If i don’t have node, how to configure babel?
thx

0 Likes

#2

Babel is written in JavaScript and thus requires node to use it.

0 Likes

#3

Being written in JS can’t be the reason.

Babel may require node, but not everything written in JS requires node. JS is also written in JS, but JS doesn’t “require” node.

0 Likes

#4

JS isn’t written in JS. Chrome’s V8 (what node uses) and Firefox’s Cybermonkey are both written in C++. Without such a runtime you can’t run any JS and by extension babel.

1 Like

#5

Er, no, i meant JS code that I write is, obviously, written in JS.
It doesn’t need node to run.

0 Likes

#6

You mostly certainly need a JS vm, like the one node ships with, in order to run any JS. And since Babel is written in JS, specifically for node, you will need node in order to use Babel.

1 Like

#7

or like the one Sublime ships with? Or the one any browser ships with?

That may be the difference. Depending on which JS Babel is written in. Not simply “because it’s written in JS”.

0 Likes

#8

Practically all non-gui desktop JS programs use node to run. Babel being a compiler (ie. not a gui application) and you wanting to use it with Sublime Text would imply that you will need node to run it. While you can run babel from a browser, I don’t see why you’d want to for an actual project or what it has to do with Sublime Text in that case.
Sublime Text only comes with a python interpreter. We don’t ship any JS runtimes.

2 Likes

#9

How? Like this?

For development environment, without having to install node. I have a very low-resource machine, and my impression is that node is a rather large disk footprint, and rather large RAM footprint. No?

Why not like this?
https://www.thegeekstuff.com/2016/12/babel-for-javascript/

or

Btw, how does Sublime do JS code-highlighing?

thx

0 Likes

#10

Node uses the same VM as chrome. The difference between running babel with node and with chrome isn’t going to be much. I can’t attest to the disk usage, but I can’t imagine it being as much as a web browser.
Using babel on the frontend is nice for short demos, but you’re forcing every visitor to a site to run your compile steps every time they load the page. It’s not a solution you’d use for an actual project with users.
Sublime Text uses syntax definitions to do code highlighting: https://www.sublimetext.com/docs/3/syntax.html

1 Like

#11

i’m only talking about my development environment.

for a live site, i assume one would release the transpiled code, not run babel on the server. Is that not typical?

but in my dev environment, i’m running a browser anyway. i assume that running chrome plus node is going to consume more RAM than chrome alone.

0 Likes

#12

From my reading of the standalone babel usage it seems like having a mixed usage where in your development environment you’re using the standalone and in production you’re using precompiled would be a lot more extra work than just always precompiling.
For a live site it depends on your deployment mechanism. But if you’re not compiling in your development environment then it would need to be done on a server somewhere.

Considering chrome runs a separate process, and thus separate JS VM, per tab, I don’t see how running it separately in node would use significantly more memory.
Why not just try running babel with node and seeing if it fits with your hardware limitations? Either it’s fine and you can just use node, or it’s not and you’ll need to find some other way to run babel.

0 Likes