zappajs-plugin-client

1.1.1 • Public • Published

@client and @browser plugin for ZappaJS

Usage

Zappa ->

  @with 'client'

  @client '/app.js': ->
    # your code here

is equivalent to

  @browser '/app.js': ->
    (require 'zappajs-client') ->
      @ready ->
        # your code here

@browser

Zappa ->
  @with 'client'
  @browser '/with-dom.js', ->

    $ = require 'component-dom'
    $('#hello').html 'Hello world!'

Serves the function, browserified, as /with-dom.js, with content-type application/javascript.

Notice that since we cannot retrieve the original CoffeeScript code from the Javascript compiled version, there could be conflicts with the helper functions' names. Therefor avoid using the following names as variables: slice, hasProp, bind, extend, ctor, indexOf, and modulo.

@client

This function is particularly useful to build client-side application that require the zappajs-client module:

Zappa ->
  @with 'client'
  @client '/app.js', ->
    Debug = require 'debug'
    Debug.enable '*'

    pkg = require './package.json'
    debug = Debug "#{pkg.name}:app"

    debug 'Starting client'

    @on 'server-said', (data) ->
      @emit 'ok', data+4

Fallback

You can still use browserify-middleware to build bundles from independent source files:

Browserify = require 'browserify-middleware'
# You may explicitely set the dependencies via `settings`
Browserify.settings transform: ['coffeeify']
# or use [`browserify.transform` in your `package.json`](https://github.com/substack/node-browserify#browserifytransform).

Zappa ->
  # It would be nice to have this as the default `engine` in ZappaJS.
  @get '/my-app.js', Browserify './client/app.coffee'

Test

Note that since this module calls itself (client-side) during the tests, you should npm link ; npm link zappajs-plugin-client before attempting npm test.

Readme

Keywords

Package Sidebar

Install

npm i zappajs-plugin-client

Weekly Downloads

18

Version

1.1.1

License

Unlicense

Last publish

Collaborators

  • shimaore