Skip to content

Commit

Permalink
Adds support for user-defined browserify transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
AtiX committed Sep 10, 2016
1 parent 2515e4a commit 101ad3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ If you use multiple plugins that require mongoose, it's probably best to specify
package.json and then hand this instance down to plugins (including serverbricks) in order to prevent strange bugs
resulting out of different required versions.

**browserify**

- `additionalTransfomrs` defines an array of transforms to be applied as well (next to coffeeify which is always active)
- `externalModules / externalBundleName` defines what modules are external (array) and how the bundle is to be named (default : `shared.js`)
- `developmentMode` defines whether to apply production settings or not. Defaults to true.
- `bundleName` defines how to name the code bundle, defaults to `client.js`

## Development
Although the ideas and most of the code of ServerBricks is used in multiple production apps, the module itself is fairly new
and still needs some work and polishing - feel free to file issues and create pull requests.
Expand Down
18 changes: 11 additions & 7 deletions src/availableBricks/browserifyCode.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
directoryUtils = require '../utils/directoryUtils'
path = require 'path'
fs = require 'fs'
browserify = require 'browserify-middleware'
coffeeify = require 'coffeeify'

Brick = require '../Brick'

# Configure browserify to work with coffeescript
coffeeify = require 'coffeeify'
browserify = require 'browserify-middleware'
browserify.settings({
transform: [coffeeify]
})

# Looks for code in the module/client directory and requires each top level file.
# Served as 'client.js' bundle
module.exports = class BrowserifyCode extends Brick
Expand All @@ -20,6 +15,7 @@ module.exports = class BrowserifyCode extends Brick
@externalBundleName = config.externalBundleName || '/shared.js'
@bundleName = config.bundleName || '/client.js'
@developmentMode = if config.developmentMode? then config.developmentMode else true
@additionalTransforms = if config.additionalTransforms? then config.additionalTransforms else []

# called before any modules are initialized
prepareInitialization: (@expressApp, @log) =>
Expand Down Expand Up @@ -54,6 +50,14 @@ module.exports = class BrowserifyCode extends Brick
else
browserify.settings.mode = 'production'

# Use coffeeify and other user specified transforms
usedTransforms = [coffeeify]
for transform in @additionalTransforms
usedTransforms.push transform
browserify.settings({
transform: usedTransforms
})

@expressApp.get @externalBundleName, browserify(@externalModules, {
cache: true
precompile: true
Expand Down

0 comments on commit 101ad3c

Please sign in to comment.