From 101ad3c9e6a94eb9843798ae6f61753ff4987101 Mon Sep 17 00:00:00 2001 From: Arthur Silber Date: Sat, 10 Sep 2016 14:10:11 +0200 Subject: [PATCH] Adds support for user-defined browserify transforms --- README.md | 7 +++++++ src/availableBricks/browserifyCode.coffee | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ae33ca5..1222c6f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/availableBricks/browserifyCode.coffee b/src/availableBricks/browserifyCode.coffee index e22647e..835cbfc 100644 --- a/src/availableBricks/browserifyCode.coffee +++ b/src/availableBricks/browserifyCode.coffee @@ -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 @@ -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) => @@ -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