Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JS require() without Node.js

This is probably a lame question, but how can you achieve the same thing as require() (Node.js) in regular JavaScript?

Some help would really be appreciated.

like image 348
Oliver Ni Avatar asked Feb 17 '14 00:02

Oliver Ni


1 Answers

There are several services that let you do this.

The most popular is Browserify.

Basically, it entails going through the file reading through the syntax tree and converting it to the a style similar to what RequireJS does.

Note that this requires an extra compilation step. (We will eventually get modules in ES6 though so there's that :) )

like image 113
Benjamin Gruenbaum Avatar answered Sep 26 '22 23:09

Benjamin Gruenbaum