lasso-tools
The lasso-tools
module helps building static applications easier
by leveraging marko and
lasso.
It is both a build tool and runtime development tool.
You use lasso-tools
by first installing the module into your project.
Installation
npm install lasso-tools --save
Next add the following files to the root of your project:
-
lasso-project.js
: This file is exports a project that is instantiated via:moduleexports = ; -
build.js
: This file is the entry point for your build which done via the following command:node build.js -
server.js
: This file is the entry point for running a local development server.node build.js
The contents of these files will be described more thoroughly below.
Quick Start Guide: Hello World
mkdir lasso-tools-hello-worldcd lasso-tools-hello-world git init npm init # name: (lasso-tools-hello-world) # version: (1.0.0) # description: # entry point: (build.js) # test command: # git repository: # keywords: # author: # license: (ISC) # Install lasso-tools into your project npm install lasso-tools@latest --save # Install lasso-babel-transform into your project npm install lasso-babel-transform@latest --save # Marko is the templating engine that `lasso-tools` uses npm install marko@latest --save # `app-module-path` is used to load modules via absolute paths # relative to the application root versus always using relative paths. npm install app-module-path@latest --save # `browser-refresh` is used to automatically restart the server # when source file is changed npm install browser-refresh@latest --save-dev
Create Boilerplate Files
.gitignore
Add a .gitignore
to the root of your project that contains:
.git/
node_modules/
static/
.cache/
*.marko.js
dist/
lasso-project.js
At the root of your project create a lasso-project.js
file with
the following contents:
var PROJECT_NAME = 'lasso-tools-hello-word'; var babelTransform = transform: config: extensions: '.js' '.es6' ; moduleexports = // Parse the command-line // (parsing will happen when server or build starts // but before configuration) ;
build.js
// The following line adds the project root directory to the// module search path which allows you to require modules// via something similar to:// require('src/util/ajax.js'); // The following line installs the Node.js require extension// for `.marko` files. Once installed, `*.marko` files can be// required just like any other JavaScript modules.; // Create a builder // Extend the configuration to allow custom command-line arguments // Start the build start { // build complete if err throw err; // If you want to do something with the resultant routes, you can // use `result.getRoutes()`... result; };
server.js
// The following line adds the project root directory to the// module search path which allows you to require modules// via something similar to:// require('src/util/ajax.js'); // The following line installs the Node.js require extension// for `.marko` files. Once installed, `*.marko` files can be// required just like any other JavaScript modules.; // We are creating a server from the project // Add a route that is only available at runtime during development // (this route won't be part of a static build) // Start the server start { if err throw err; };
src/pages/app/index.marko
lasso-page package-path="./browser.json" lasso=data.lasso name=data.pageName
<!DOCTYPE html>
html
head
meta charset="utf-8"
title - Hello World
lasso-head
body
lasso-body
browser-refresh enabled="true"
init-widgets
src/pages/app/browser.json
Start Development Server
Start server without using browser-refresh
:
node server.js --http-port 8000
Start server using browser-refresh
and with advanced options:
BASEDIR=`dirname $0` MARKO_CLEAN=true node $BASEDIR/node_modules/.bin/browser-refresh "$BASEDIR/server.js" --config config-dev.properties --ssl-cert server.crt --ssl-key server.key
Example configuration properties file:
# Specify HTTP port
http-port = 8888
# Minify JavaScript and CSS files
minify = true
Open http://localhost:8888/
and you should see "Hello World!".
Build Project
Development build:
# Recommend deleting .cache and dist directory before build rm -rf dist .cache node build.js
Production build:
# Recommend deleting .cache and dist directory before build rm -rf dist .cache node build.js --production true
Command Line Help
Help for server command:
node server.js --help
Help for build command:
node build.js --help