0.3.10 • Published 7 years ago

unv v0.3.10

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

unv

Build status Git tag NPM version Code style

Universal, javascript-only application dev server and build tool.

Installation

$ npm install unv

Overview

unv is not trying to be everything for everyone. It's designed to work very well with the way we bootstrap projects at Weo. If your projects are like ours, it'll be great. If not, look into something like budo which is less opinionated.

CLI

If you have a src/client.js or a lib/client.js (in that order), then you can just run:

unv dev

In your project's root. If you want more options, then...

Options

  • --port <port> - Port to listen on. Defaults to 3000.
  • --server <file> - Server entrypoint
  • --client <file> - Client entrypoint
  • --modules <dir> - Root module folder. E.g. src/. This folder will be added to the module resolution path, so that you can require from it directly. E.g. require('components/modal'), assuming your src folder contains a 'components' folder. This is of course in addition to node_modules. All of your transforms / babel plugins will run on these modules without issue (often there are problems with this if you try to use symlinks from node_modules).

client.js

Doesn't need to export anything - just your clientside entrypoint and the first thing that will run in the browser. Example:

import domready from '@f/domready'
import vdux from 'vdux/dom'

domready(() => vdux({
  app,
  middleware,
  reducer
}))

server.js

Your server.js file should export a single function of the form render(request, urls). urls.js is the path to your javascript bundle, and request is a node request object. Your render function may return any yieldable value (e.g. promise, string, thunk, generator, etc.) that resolves to the HTML of the page you want to render.

Example:

export default function *(req, urls) {
  const {state, html} = yield main(req)

  return `
    <html>
      <head>
        <script type='text/javascript'>
          window.__initialState__ = ${JSON.stringify(state)}
        </script>
        <script type='text/javascript' src='${urls.js}'></script>
      </head>
      <body>
        ${html}
      </body>
     </html>
     `
}

Hot reloading

Hot reloading is turned on by default in the dev server, and since everything is javascript, it's the only type of reloading you'll need (i.e. no livereload). To support server-side hot reloading, your server.js may export a replace method.

Here's an example replace function:

function replace () {
  invalidate(new RegExp('^' + path.resolve('./src')))
  main = require('./main').default
}

function invalidate (re) {
  forEach(remove, require.cache)

  function remove (val, key) {
    if (re.test(key)) {
      delete require.cache[key]
    }
  }
}

Client-side hot reloading works using the browserify-hmr plugin.

Assets (e.g. images)

In both your server-side and client-side code, you can just require/import any assets you may have and it will resolve to the url it's going to be served from. E.g.

import weo from './weo.png'
import element from 'vdux/element'

function render () {
  return <img src={weo} />
}

export default render

CSS

There is currently not a particular solution for css. Which means you're mostly limited to css-in-js solutions at the moment. At Weo, we use jss-simple.

Building for production

unv will also support building all of your assets and an asset map (similar to webpack's) for production, but that is still TBD.

ES6

All of your code (server and client) will be babel'd from the start. So no need for any server.babel.js or anything like that.

License

MIT

0.3.10

7 years ago

0.3.9

8 years ago

0.3.8

8 years ago

0.3.7

8 years ago

0.3.6

8 years ago

0.3.5

8 years ago

0.3.4

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.33

8 years ago

0.2.32

8 years ago

0.2.31

8 years ago

0.2.30

8 years ago

0.2.29

8 years ago

0.2.28

8 years ago

0.2.27

8 years ago

0.2.26

8 years ago

0.2.25

8 years ago

0.2.24

9 years ago

0.2.23

9 years ago

0.2.22

9 years ago

0.2.21

9 years ago

0.2.20

9 years ago

0.2.19

9 years ago

0.2.18

9 years ago

0.2.17

9 years ago

0.2.16

9 years ago

0.2.15

9 years ago

0.2.14

9 years ago

0.2.13

9 years ago

0.2.11

9 years ago

0.2.10

9 years ago

0.2.9

9 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago