diff --git a/README.md b/README.md index 8ba67ba4..cffd59d0 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,9 @@ Return a `css` stream using [sheetify](https://github.com/stackcss/sheetify). ### assets.js(browserify, src, opts?) Return a `js` stream. `src` is the bundle entry file. `opts` are passed directly to `browserify` +- __opts.id__ id to expose the root bundle as via `require()`. Defaults to `bankai-app` +- __opts.basedir__ directory to resolve `src` from. Defaults to `process.cwd()` +- __opts.fullPaths__ use full module paths as module ids. Defaults to `true` ## CLI @@ -115,7 +118,7 @@ $ node ./bin/ --help Projects showing exemplary usage are provided. Install root project dependencies, example project dependencies and execute `npm start` to start an example. -- [Basic](./example/basic) - Showing default settings, Hot Module Replacement +- [Basic](./example/basic) - Minimal CLI and API usage ## See Also - [budo](https://www.npmjs.com/package/budo) diff --git a/example/basic/.gitignore b/example/basic/.gitignore new file mode 100644 index 00000000..849ddff3 --- /dev/null +++ b/example/basic/.gitignore @@ -0,0 +1 @@ +dist/ diff --git a/example/basic/package.json b/example/basic/package.json index bc318e78..b7b00b8c 100644 --- a/example/basic/package.json +++ b/example/basic/package.json @@ -4,7 +4,9 @@ "description": "Basic example of using bankai", "main": "index.js", "scripts": { - "start": "../../bin/index.js start --css.use sheetify-cssnext" + "start": "../../bin/index.js start --css.use sheetify-cssnext", + "build": "../../bin/index.js build --css.use sheetify-cssnext", + "server": "node server.js" }, "license": "MIT", "dependencies": { diff --git a/example/basic/readme.md b/example/basic/readme.md index ea90877f..02ab5690 100644 --- a/example/basic/readme.md +++ b/example/basic/readme.md @@ -5,7 +5,9 @@ of developers looking into bankai as development tool. ## Features -* Easy cli usage of default bankai +* Easy cli usage of default bankai server `npm start` +* Builds via `npm run build` +* Minimalistic bankai server implemented with node api `npm run server` * Scoped styles via sheetify ## Installation @@ -17,5 +19,7 @@ npm install ## Usage ```shell -npm start +npm start # start a default bankai server via "bankai start" cli +npm run build # run default bankai build process via "bankai build" cli +npm run server # run a minimal bankai server via bankai node api ``` diff --git a/example/basic/server.js b/example/basic/server.js new file mode 100644 index 00000000..7cff67f6 --- /dev/null +++ b/example/basic/server.js @@ -0,0 +1,24 @@ +'use strict' + +const serverRouter = require('server-router') +const browserify = require('browserify') +const bankai = require('../../')() +const http = require('http') + +const html = bankai.html() +const css = bankai.css({use: ['sheetify-cssnext']}) +const js = bankai.js(browserify, './index.js', {basedir: __dirname}) + +const routes = [ + ['/', html], + ['/404', html], + ['/bundle.css', css], + ['bundle.js', js] +] + +const router = serverRouter('/404', routes) +const server = http.createServer((req, res) => router(req, res).pipe(res)) + +server.listen(1337, () => { + console.log('Started bankai on http://localhost:1337') +}) diff --git a/handler-js.js b/handler-js.js index 08f96f50..7e3b6432 100644 --- a/handler-js.js +++ b/handler-js.js @@ -29,19 +29,18 @@ function js (state) { opts: opts } - const resolvedSrc = require.resolve(src) - const baseBrowserifyOpts = { id: 'bankai-app', + basedir: process.cwd(), cache: {}, packageCache: {}, - entries: [resolvedSrc], + entries: [src], fullPaths: true } const browserifyOpts = xtend(baseBrowserifyOpts, opts) var b = browserify(browserifyOpts) - b.require(resolvedSrc, { + b.require(src, { expose: browserifyOpts.id })