- simple web server
- easy to extend with API
- auto watch / build, recursive tree parsing
- as a module, but extensible.
install required modules
npm install --save @zbryikt/template
start server ( -r, -p and -c are optional ):
npx server -r <your-web-root> -c <your-server-config> -o <auto-open:true/false> -p <port>
By default assets won't be copied but you can specify extensions to copy with comma-separated strings:
npx server -r <your-web-root> -m png,jpg,jpeg,gif
or use srcbuild's default values by passing true:
npx server -r <your-web-root> -m true
you can also add following in your own package.json:
"scripts": {
"start": "npx server"
},
optional server config json file specified via -c option for altering default port and other config:
{ "port": 3012 }
Port will be randomized unused port if not specified. For more about options, see the Options section below.
sample folder serves as a starting point to bootstrap a project. It contains following files:
package.json: a simple package.json with necessary dependencies. You need to update repo info in this.LICENSE: default MIT.config.json: config file used by template.deploy: if you use gh-pages of github, this automatically push your static/ directory to gh-pages branch. you need to have a gh-pages branch at first.README.md: a dummy readme. edit it as necessary.src/: template style source code folder. check@plotdb/srcbuildfor more information.src/ls/: LiveScript code, built to static/js/src/pug/: Pug code, built to static/src/styl/: Stylus code, built to static/css/
static/: generated files or other assets.locales/: i18n translation files based oni18next.
run template with customized web api by manually initing server:
require("template")
template.server.init({
api: function(server) {
server.app.get("/custom-api", function(req, res) {
return res.send("custom api response");
});
}
});
in this case you will have to watch source files manually:
template.watch.init({ ... });
server.init accepts config with following options:
port- port to listen. when omitted, random unused port is used.startTime- optional time for providing initialization elapsed time information.api- functions for customizing server. executed before server startedopen- true to open browser page when server starts. default falseferoot- frontend root for serving static file and building view files. default..i18n- i18n options including:enabled- true if i18n is enabled. defaulttrue.lng- list of locales. default['zh-tw']. mapped to folders underlocales/directory.fallbackLng- fallback locales. defaultzh-tw.preload- list of locales to preload. defalt['zh-tw'].ns- list of namespaces. default['default']. mapped to files under specific locale directory.defaultNS- default namespace. defaultdefaultfallbackNS- fallback namespace when failed to match with desired namespace. defaultdefault.
for using @zbryikt/template as a command line tool, config file specified by -c option also support following options:
lsp: an object passed tosrcbuild.lspas options. check@plotdb/srcbuildfor more information.
watch.init accepts config with following options:
watcherignores: files to ignored ( not watched ). array of regular expression against file names.
assets: (deprecated) array of node module names to be copied tostatic/assetsfolder.- replaced by
fedep. will be removed in future release
- replaced by
template now use @plotdb/srcbuild for source building, and thus there are some additional features available and documented in @plotdb/ssrcbuild. Please refer to @plotdb/srcbuild for more information.
- support both indir building or src / static building.
- api style invocation
- To optimize Pug building, keep an eye on the Pug inclusion tree, and prevent unnecessary include if possible.
MIT