Run live web and build static site
Suppose that we want to build a front-end only website with pure HTML/CSS/JS or React, Vue, whatever. Our repo may look like following folder structure:
my-project - package.json - src/ - assets - css - main.css - theme.css - js - main.js - another-modules.js - static - fonts - images - favicon.ico - templates - index.html - about.html - faq.html - config.json
Here the website source code is placed within
src folder. However the folder name can be anything else.
templates dir is not required. If it does exist,
webrender will try to parse them with nunjucks template engine. Otherwise, the HTML files located at root folder will be used.
examples/ for reference.
In order to use
webrender, let's install it:
npm i webrender
Then you can use it with command line or call it from code.
Add these 2 commands to
script section of the
package.json file, for example:
Since now, we can run the website within
src folder to view and develop it as below:
npm run dev
Once everything is ok, we can build a static site into
npm run build
Run a website located at
const run = ;;
This approach is helpful to work with
nodemon for auto reloading.
You can even add more express middlewares:
const path = ;const cors = ;const favicon = ;const middlewares =;;
Lastly, just build static version of this website to
const build = ;;
git clone email@example.com:ndaidong/webrender.gitcd webrendernpm inpm test
The MIT License (MIT)