• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A set of conventions and tools for bundle and serving clientside apps with node.js

moonboots

Moonboots makes it incredibly easy to jump into single-page-app development by encapsulating a set of conventions and tools for building, bundling, and serving SPAs with node.js.

Powered by browserify, moonboots gives us a structured way to include non-CommonJS libraries, work in development mode and agressively cache built JS and CSS files for production.

What it does

  1. Saves us from re-inventing this process for each app.
  2. Lets a developer focus on building a great clientside experience, not boiler plate.
  3. Lets you use CommonJS modules to structure your clientside code.
  4. Manages clientside files during development so you can just write code.
  5. Compiles/minifies/uniquely named JS files (and CSS files optionally) containing your application allowing really aggressive caching (since the name will change if the app does).
  6. Plays nicely with express.js, hapi.js, or even straight node http

Why?

  1. Because single page apps are different. You're shipping an application to be run on the browser instead of running an application to ship a view to the browser.
  2. Engineering a good client-side app requires a good set of conventions and structure for organizing your code.
  3. Effeciently building/sending a client-side app to the browser is a tricky problem. It's easy to build convoluted solutions. We want something a bit simpler to use.

How to use it

You grab your moonboots, pass it a config and listen for the ready event. Then tell your http library which urls to serve your single page app at.

That's it.

var express = require('express');
var Moonboots = require('moonboots');
var app = express();

// configure our app
var clientApp = new Moonboots({
    main: __dirname + '/sample/app/app.js',
    libraries: [
        __dirname + '/sample/libraries/jquery.js'
    ],
    stylesheets: [
        __dirname + '/styles.css'
    ]
});

clientApp.on('ready', function () {
    app.get(clientApp.jsFileName(),
        function (req, res) {
            clientApp.jsSource(function (err, js) {
                res.send(js);
            })
        }
    );
    app.get('/app*', clientApp.htmlSource());

    // start listening for http requests
    app.listen(3000);
});

Options

Available options that can be passed to Moonboots:

  • main (required, filepath) - The main entry point of your client app. Browserify uses this to build out your dependency tree.
  • libraries (optional, array of file paths, default: []) - An array of paths of JS files to concatenate and include before any CommonJS bundled code. This is useful for stuff like jQuery and jQuery plugins. Note that they will be included in the order specified. So if you're including a jQuery plugin, you'd better be sure that jQuery is listed first.
  • stylesheets (optional, array of file paths, default: []) - An array of CSS files to concatenate
  • jsFileName (optional, string, default: app) - the name of the JS file that will be built
  • cssFileName (optional, string, default: styles) - the name of the CSS file that will be built
  • browserify (optional, object, default: {debug: false}) - options to pass directly into browserify, as detailed here. Additional options are:
    • browserify.transform (optional, list, default: []) - list of transforms to apply to the browserify bundle, see here for more details.
  • uglify (optional, object, default: {}) - options to pass directly into uglify, as detailed here
  • modulesDir (optional, directory path, default: '') - directory path of modules to be directly requirable (without using relative require paths). For example if you've got some helper modules that are not on npm but you still want to be able to require directly by name, you can include them here. So you can, for example, put a modified version of backbone in here and still just require('backbone').
  • beforeBuildJS (optional, function, default: nothing) - function to run before building the browserify bundle during development. This is useful for stuff like compiling clientside templates that need to be included in the bundle. If you specify a callback moonboots will wait for you to call it. If not, it will be run synchronously (by the magic of Function.prototype.length).
  • beforeBuildCSS (optional, function, default: nothing) - function to run before concatenating your CSS files during development. This is useful for stuff like generating your CSS files from a preprocessor. If you specify a callback moonboots will wait for you to call it. If not, it will be run synchronously (by the magic of Function.prototype.length).
  • sourceMaps (optional, boolean, default: false) - set to true to enable sourcemaps (sets browserify.debug to true)
  • resourcePrefix (optional, string, default: '/') - specify what dirname should be prefixed when generating html source. If you're serving the whole app statically you may need relative paths. So just passing resourcePrefix: '' would make the template render with <script src="app.js"></script> instead of <script src="/app.js"></script>.
  • minify (optional, boolean, default: true) - an option for whether to minify JS and CSS.
  • cache (optional, boolean, default: true) - an option for whether or not to recalculate the bundles each time
  • buildDirectory (optional, string, default: nothing) - directory path in which to write the js and css bundles after building and optionally minifying. If this is set, moonboots will first look in this folder for files matching the jsFileName and cssFileName parameters and use them if present. Those files will be trusted implicitly and no hashing or building will be done.
  • developmentMode (optional, boolean, default: false) - If this is true, forces cache to false, minify to false, and disables buildDirectory
  • timingMode (optional, boolean, default: false) - If set to true, moonboots will emit log events w/ a 'timing' flag at various stages of building to assist with performance issues

About Source Maps

Sourcemaps let you send the actual code to the browser along with a mapping to the individual module files. This makes it easier to debug, since you can get relevant line numbers that correspond to your actual source within your modules instead of the built bundle source.

Please note that if you are using libraries your line numbers will be off, because that prepends those files to the main bundle. If it is important for you to maintain line numbers in your source maps, consider using browserify-shim in your transforms to include those non-commonjs files in your app

Methods

moonboots.jsFileName() - returns string of the current js filename.

moonboots.jsSource() - returns compiled (and optionally minified js source)

moonboots.cssFileName() - returns string of the current css filename.

moonboots.cssSource() - returns concatenated (and optionally minified css stylesheets)

moonboots.htmlSource() - returns default html to serve that represents your compiled app w/ a script and optional style tag

moonboots.htmlContext() - returns object w/ jsFileName and cssFileName attributes to pass to your http server's templating engine to build your own html source

Full example

For a working example, check out moonboots-hapi or moonboots-express or even moonboots-static

License

MIT

More Repositories

1

hjs-webpack

Helpers/presets for setting up webpack with hotloading react and ES6(2015) using Babel.
JavaScript
1,789
star
2

ICanHaz.js

A clean solution for templating with Mustache.js and jQuery or Zepto
JavaScript
837
star
3

feather-app

as light as a...
JavaScript
718
star
4

create-keyframe-animation

Generate CSS keyframe animations dynamically in the browser with JavaScript.
JavaScript
716
star
5

redux-bundler

Compose a Redux store out of smaller bundles of functionality.
JavaScript
581
star
6

fixpack

A package.json file scrubber for the truly insane.
JavaScript
461
star
7

Capsule

Realtime web app framework for Backbone, socket.io and node.js
JavaScript
415
star
8

Happy.js

$('form').isHappy() – Lightweight, extensible form validation plugin for jQuery/Zepto.js
JavaScript
412
star
9

html-parse-stringify

Parses well-formed HTML (meaning all tags closed) into an AST and back. quickly.
JavaScript
337
star
10

templatizer

Simple solution for compiling jade templates into vanilla JS functions for blazin' fast client-side use.
JavaScript
303
star
11

money-clip

For managing your client side cache. Tiny wrapper over IndexedDB supporting versioning and max age.
JavaScript
233
star
12

wildemitter

A super lightweight EventEmitter similar to what comes in Node.js, but with a support for wildcard events '*'
JavaScript
213
star
13

emoji-images

replace stuff like ❤️ with <img> tags of corresponding images per: http://www.emoji-cheat-sheet.com/
JavaScript
173
star
14

webrtc.js

WebRTC abstraction for managing it simple to manage multiple peer connections of various types.
JavaScript
158
star
15

hubtags.com

A demo app, built with Ampersand and React as a static Native Web App
JavaScript
137
star
16

getconfig

Config file reader for node.js projects that detects environment based on NODE_ENV.
JavaScript
116
star
17

andlog

Super-simple, client-side CommonJS logging thingy
JavaScript
97
star
18

github-secret-keeper

Microservice to enable GitHub login for multiple server-less applications.
JavaScript
86
star
19

human-javascript

Book on building sanely architected JS apps
CSS
80
star
20

human-model

Strict models are a drop-in replacement for Backbone models but are far more restrictive and structured.
JavaScript
75
star
21

humanjs-sample-app

Sample app for human javascript book
JavaScript
67
star
22

milliseconds

Insanely lightweight module for converting times to milliseconds.
JavaScript
62
star
23

masters

Repo to follow along with Frontend Masters class
JavaScript
60
star
24

redux-bundler-worker-example

Redux-bundler with store and bundler running inside a worker
JavaScript
58
star
25

clientconfig

Super simple clientmodule for passing config items, such as API connection URLs, debug modes, etc from server to client.
JavaScript
56
star
26

webrtcsupport

Browser module to detect support for WebRTC and extract proper constructors.
JavaScript
55
star
27

internal-nav-helper

Helper function for handling internal navigation in Single Page Apps (SPAs) in ~250 bytes before gzip.
JavaScript
52
star
28

feather-route-matcher

featherweight url to handler matching
JavaScript
42
star
29

redux-bundler-react

Bindings for redux-bundler to React
JavaScript
37
star
30

redux-bundler-example

Example app built with redux-bundler
JavaScript
34
star
31

human-view

A smart base view for Backbone apps, to make it easy to bind collections and properties to the DOM.
JavaScript
33
star
32

humanjs

Application scaffolding and documentation repo for Human JavaScript Apps
JavaScript
32
star
33

ric-shim

requestIdleCallback shim that won't blow up if used in node.js
JavaScript
29
star
34

featherweight

JavaScript
28
star
35

reformer

Self-contained, self-rendering, self-validating forms that can only output valid data.
JavaScript
26
star
36

hapi-dummy-api

Generate dummy APIs for hapi.js, for building clientside apps before the real API is done.
JavaScript
26
star
37

worker-proof

Enables calling out to main thread from a worker to register callbacks, etc.
JavaScript
26
star
38

redux-persist-middleware

Creates Redux middleware that will lazily persist data from certain reducers, when certain actions occur.
JavaScript
26
star
39

react-internal-nav

React component with single 'onInternalNav' callback for handling clicks on <a> local to domain.
25
star
40

babel-plugin-h-children-fix

Allows use of standard babel JSX tools with virtual-dom/h
JavaScript
25
star
41

appcache-serviceworker-generator

Can generate an appcache manifest and ServiceWorker from same abstraction.
JavaScript
24
star
42

image-to-data-uri.js

Clientside module (compatible with clientmodules) that takes an image url, downloads the image and creates a data URI for caching, etc.
JavaScript
23
star
43

tryit

Module to wrap try-catch for better performance and cleaner API.
JavaScript
22
star
44

window-watcher

State object you can listen to for changes to window width.
JavaScript
19
star
45

slugger

Dead simple string slugification (a. la. django) for node and the broswer.
JavaScript
18
star
46

create-selector

Wrapper for reselect to allow deferring creation of selectors.
JavaScript
18
star
47

native-promisify-if-present

Return a promise from a callback-as-last-argument function using native a Promise, but only if native Promises exist.
JavaScript
17
star
48

jquery-sliding-message

Nice way to show messages to users
JavaScript
16
star
49

semi-static

Simple, lazy way to serve a directory of semi-static pages in express.js. Handy for building quick "static" pages inside an otherwise "dynamic" app.
JavaScript
15
star
50

key-tree-store

Simple tool for storing/retrieving objects events based hierarchical key paths.
JavaScript
14
star
51

dot-net-article

13
star
52

loading-stats

Client module for reporting real-world single page application performance back to you in your metrics.
JavaScript
13
star
53

video-recorder

Experimental browser module for recording contents of a `<video>` tag by taking dataURI snapshots of it.
JavaScript
12
star
54

set-query-string

Updates the browser's query string in place, so you can bind it to some dynamic query in your app
JavaScript
11
star
55

fluent-2016

Building a lightweight mobile-web app with React and Redux
JavaScript
11
star
56

time-counter

Dead-simple js module for drawing (or simply measuring) time countdowns or counters in js. Works in node and browser.
JavaScript
11
star
57

timple

Simple templating for service workers using valid javascript files as the template
JavaScript
11
star
58

sinks

Tools for object sync (get it?!), validation, diffing, and immutable deep setting
JavaScript
10
star
59

Yo-Moma

Nerdpoints for the best nerdy yo mama joke. Bonus points for git references.
10
star
60

joreteg.com

My new site
HTML
9
star
61

system-requirements.js

Boxed software has 'em, now the web does too.
JavaScript
9
star
62

jquery.dd

Simple replacement for select boxes that are totally css stylable
JavaScript
9
star
63

favicon-setter

Dead-simple favicon updating from JS. Plays nicely with jQuery and CommonJS but has no dependencies.
JavaScript
9
star
64

redux-bundler-worker

Utilities for running a redux-bundler app inside a worker
JavaScript
9
star
65

clientmodules

A small util for using npm to install clientside packages.
JavaScript
8
star
66

fingertips

Touch event handling for mobile web apps
JavaScript
8
star
67

columnizer

A simple tool for printing text in nice columns in the terminal.
JavaScript
8
star
68

redux-bundler-preact

Preact bindings for redux-bundler
JavaScript
8
star
69

jquery-magic-labels

Grabs content of label tag to display as placeholder inside text inputs
JavaScript
8
star
70

wake-event

Browser module for detecting when your computer wakes up from sleep. Based on Alex MacCaw's clever trick.
JavaScript
7
star
71

preact-nav-helper

Preact component for catching and handling internal links in your application.
JavaScript
7
star
72

mit.joreteg.com

license site I can link to from open source projects
HTML
6
star
73

bind-transforms

Bind models properties to properly prefixed CSS transforms in backbone/humanjs views.
JavaScript
6
star
74

humanjs-resources

Curated collection of simple modules solving specific problems relating to building single page apps.
JavaScript
6
star
75

SoundEffectManager

A simple sound effect manager for playing sounds using the awesome HTML 5 Web Audio API
JavaScript
6
star
76

library-api

Simple, restful, demo JSON API written in Hapi.js
JavaScript
6
star
77

ampersand-local-cache-mixin

Only fetch when your data is old or stale. Easily configurable localStorage cache for ampersand & backbone state objects, models, and collections.
JavaScript
6
star
78

transform-style

Apply transform style property with proper prefix to an element. For use with browserify / CommonJS.
JavaScript
5
star
79

holy-grail-ios-layout

Attempt at holy grail mobile safari layout/behavior.
JavaScript
5
star
80

edui

Codebase for edui workshop
JavaScript
5
star
81

labelr-ampersand

class outline and resources
JavaScript
5
star
82

jsconfbr

Sample code for simple webrtc demo
JavaScript
5
star
83

statey

An observable, extensible state object with derived watchable properties.
JavaScript
5
star
84

extend-object

Underscore's extend method as a standalone Common JS module.
JavaScript
5
star
85

google-cloud-signedurl-test-case

Trying to figure out how to make this work :-/
JavaScript
5
star
86

array-next

Advance to the next item in the array looping when hitting the end.
JavaScript
5
star
87

cookie-getter

Super simple, performant, clientside cookie reader and nothing else. CommonJS and clientmodules compatible.
JavaScript
5
star
88

Half-SASS

A partial SASS implementation written in CF
ColdFusion
4
star
89

add-keyup-events

Emit custom events from an input so you can do stuff like listening for "enter" and "esc" events the same way as you would "keyup".
JavaScript
4
star
90

humanjs-codealong-app

JavaScript
4
star
91

get-css-translated-position

Get position of DOM elements positioned with CSS translate
JavaScript
4
star
92

docs.humanjavascript.com

Docs site for humanjs tools
JavaScript
4
star
93

Strophe.js-Plugins

A collection of strophe plugins that let you work with native JavaScript instead of XML
JavaScript
4
star
94

wakelock-lazy-polyfill

Use nosleep.js as a lazy-loaded polyfill for WakeLock API
JavaScript
4
star
95

rollup-plugin-css

Rollup plugin for aggregating and outputting CSS
JavaScript
4
star
96

labelr

JavaScript
3
star
97

dob-to-age

Determines current age based on a date of birth string YYYY-MM-DD using same weird logic we humans do.
JavaScript
3
star
98

reality

Physics simulation runner for web UIs
JavaScript
3
star
99

dotnet-dashboard.andbang.com

A team dashboard app for And Bang 2.0
JavaScript
3
star
100

parse-dob

Turn a wide range of freeform inputs describing someone's birth date into `YYYY-MM-DD` using locale to get proper day / month order.
JavaScript
3
star