Skip to content

Commit ed07f1c

Browse files
authored
Merge pull request #59 from marionebl/fix/resolve-js-entry-from-cwd
fix: resolve js entry from cwd
2 parents ae58fc0 + 883a2c6 commit ed07f1c

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Return a `css` stream using [sheetify](https://github.com/stackcss/sheetify).
5454
### assets.js(browserify, src, opts?)
5555
Return a `js` stream. `src` is the bundle entry file. `opts` are passed
5656
directly to `browserify`
57+
- __opts.id__ id to expose the root bundle as via `require()`. Defaults to `bankai-app`
58+
- __opts.basedir__ directory to resolve `src` from. Defaults to `process.cwd()`
59+
- __opts.fullPaths__ use full module paths as module ids. Defaults to `true`
5760

5861
## CLI
5962

@@ -115,7 +118,7 @@ $ node ./bin/ --help
115118
Projects showing exemplary usage are provided. Install root project dependencies,
116119
example project dependencies and execute `npm start` to start an example.
117120

118-
- [Basic](./example/basic) - Showing default settings, Hot Module Replacement
121+
- [Basic](./example/basic) - Minimal CLI and API usage
119122

120123
## See Also
121124
- [budo](https://www.npmjs.com/package/budo)

example/basic/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

example/basic/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "Basic example of using bankai",
55
"main": "index.js",
66
"scripts": {
7-
"start": "../../bin/index.js start --css.use sheetify-cssnext"
7+
"start": "../../bin/index.js start --css.use sheetify-cssnext",
8+
"build": "../../bin/index.js build --css.use sheetify-cssnext",
9+
"server": "node server.js"
810
},
911
"license": "MIT",
1012
"dependencies": {

example/basic/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ of developers looking into bankai as development tool.
55

66
## Features
77

8-
* Easy cli usage of default bankai
8+
* Easy cli usage of default bankai server `npm start`
9+
* Builds via `npm run build`
10+
* Minimalistic bankai server implemented with node api `npm run server`
911
* Scoped styles via sheetify
1012

1113
## Installation
@@ -17,5 +19,7 @@ npm install
1719
## Usage
1820

1921
```shell
20-
npm start
22+
npm start # start a default bankai server via "bankai start" cli
23+
npm run build # run default bankai build process via "bankai build" cli
24+
npm run server # run a minimal bankai server via bankai node api
2125
```

example/basic/server.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
const serverRouter = require('server-router')
4+
const browserify = require('browserify')
5+
const bankai = require('../../')()
6+
const http = require('http')
7+
8+
const html = bankai.html()
9+
const css = bankai.css({use: ['sheetify-cssnext']})
10+
const js = bankai.js(browserify, './index.js', {basedir: __dirname})
11+
12+
const routes = [
13+
['/', html],
14+
['/404', html],
15+
['/bundle.css', css],
16+
['bundle.js', js]
17+
]
18+
19+
const router = serverRouter('/404', routes)
20+
const server = http.createServer((req, res) => router(req, res).pipe(res))
21+
22+
server.listen(1337, () => {
23+
console.log('Started bankai on http://localhost:1337')
24+
})

handler-js.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ function js (state) {
2929
opts: opts
3030
}
3131

32-
const resolvedSrc = require.resolve(src)
33-
3432
const baseBrowserifyOpts = {
3533
id: 'bankai-app',
34+
basedir: process.cwd(),
3635
cache: {},
3736
packageCache: {},
38-
entries: [resolvedSrc],
37+
entries: [src],
3938
fullPaths: true
4039
}
4140
const browserifyOpts = xtend(baseBrowserifyOpts, opts)
4241
var b = browserify(browserifyOpts)
4342

44-
b.require(resolvedSrc, {
43+
b.require(src, {
4544
expose: browserifyOpts.id
4645
})
4746

0 commit comments

Comments
 (0)