Skip to content

Commit

Permalink
Merge pull request #59 from marionebl/fix/resolve-js-entry-from-cwd
Browse files Browse the repository at this point in the history
fix: resolve js entry from cwd
  • Loading branch information
marionebl authored Sep 4, 2016
2 parents ae58fc0 + 883a2c6 commit ed07f1c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions example/basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
4 changes: 3 additions & 1 deletion example/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions example/basic/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
24 changes: 24 additions & 0 deletions example/basic/server.js
Original file line number Diff line number Diff line change
@@ -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')
})
7 changes: 3 additions & 4 deletions handler-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down

0 comments on commit ed07f1c

Please sign in to comment.