Here's how to modify and locally test the source code of this repository. This also works for any other node apps running on the browser.
See files and code inside localTesting and the scripts defined inside package.json for the gritty details of it all.
DON'T FORGET TO NPM INSTALL
NOTE: it may be valuable to have browserify AND watchify installed globally. You can do that by running npm install -g browserify watchify
-
You must have an entry point like index.js that exports your whole module or the relevant parts using
module.exports -
You must have a master client-side script like BrowserTestScript.js that runs the parts of the code you wish to test in the browser.
We must first compile the code into a single bundle script that will be mounted on our html file that will be loaded onto the browser.
We do that by running browserify /src/BrowserTestScript.js -o /localTesting/bundle.js
This compiles the code into a single javascript file that will be imported into the HTML file.
Now you may import the file into the HTML by using the tag
<script src="bundle.js"></script>Hot reloading can be done by using watchify, which basically runs browserify every time a change is done to any of the dependencies used in your high-level script.
The script used in this project is watchify ./src/BrowserTestScript.js -o ./localTesting/bundle.js -v
This script is also bound to the shortcut npm run hot-reload in this project. Run this if you are making constant
changes to the files while testing in the browser.
Now, every time a change is made to any of the dependencies, you can simply reload the page and the changes have
been applied and compiled into bundle.js.
A simple node server has been set up for development, defined inside server.js. Please check the source code for more details.
This essentially serves index.html and bundle.js whenever localhost:4545 is fetched in the browser.
To run this server, either run node ./localTesting/server.js or npm start.
Then open localhost:4545 in your browser of choice.
- Run
npm run hot-reloadto updatejsfiles on the fly - Run
npm startto serve static files
Note: Script may be different in Windows and Linux. See watchify documentation for more details.
Written by Léo Gonsalves, condensed from this tutorial