asset-smasher
Advanced tools
Comparing version 0.2.3 to 0.2.4
# Asset Smasher Changelog | ||
## 0.2.4 (March 16, 2013) | ||
- Allow more fine-grained control over the `serve` option of the middleware (e.g. serving merged files instead of individual ones). See alternate production config in `README.md` for usage. (Fixes #7) | ||
## 0.2.3 (March 14, 2013) | ||
@@ -4,0 +8,0 @@ |
var path = require('path'); | ||
var url = require('url'); | ||
var async = require('async'); | ||
var underscore = require('underscore'); | ||
var Smasher = require('./asset-smasher').Smasher; | ||
@@ -10,5 +11,13 @@ var send = require('send'); | ||
this.prefix = options.prefix; | ||
this.serve = options.serve; | ||
var serve = options.serve; | ||
if (serve) { | ||
if (typeof(serve) !== 'object') { | ||
serve = {}; | ||
} | ||
this.serve = underscore.defaults(serve, { | ||
individual: true | ||
}); | ||
} | ||
this.debug = options.debug; | ||
if (options.serve) { | ||
if (this.serve) { | ||
this.compileQueue = async.queue(this.loadOrCompileAsset.bind(this), 1); | ||
@@ -112,3 +121,3 @@ this.smasher = new Smasher(options); | ||
/** | ||
* Create a script tag (or bunch of script tags for a manifest when serve is true) | ||
* Create a script tag (or bunch of script tags for a manifest when serve.individual is true) | ||
* for a JavaScript asset | ||
@@ -123,3 +132,3 @@ */ | ||
/** | ||
* Create a link tag (or bunch of link tags for a manifest when serve is true) | ||
* Create a link tag (or bunch of link tags for a manifest when serve.individual is true) | ||
* for a CSS asset | ||
@@ -143,3 +152,4 @@ */ | ||
* Get the assets required for the specified logical path. This will separate any | ||
* manifests into their individual files (if not running with an asset map) | ||
* manifests into their individual files (if not running with an asset map, and | ||
* serve.individual is true) | ||
*/ | ||
@@ -150,3 +160,3 @@ getAssetsForLogicalPath:function (logicalPath) { | ||
} else { | ||
if (this.serve) { | ||
if (this.serve && this.serve.individual) { | ||
var asset = this.smasher.getAssetByLogicalPath(logicalPath); | ||
@@ -153,0 +163,0 @@ if (asset) { |
{ | ||
"name": "asset-smasher", | ||
"description": "Asset pre-processor, merger, and compressor.", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"author": "Jim Riecken <jriecken@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -287,3 +287,5 @@ # Asset Smasher | ||
- `serve` - boolean whether the middleware should serve the asset files. Usualy set this to `true` in development, `false` in production | ||
- `serve` - boolean (or object - see more below) indiacating whether the middleware should serve the asset files. Usualy set this to `true` in development, `false` in production (e.g if you're using precompiled assets) | ||
- An object can be passed in with the following properties to control the serving behavior. If `true` is passed in, the default values here will be used | ||
- `individual` - Whether the individual (`true`) or merged files (`false`) should be served. Default `true`. | ||
- `assetMapLocation` - path to the `map.json` generated by the command-line `asset-smasher` util. This allows the helper methods to determine what the hashed file names were | ||
@@ -318,2 +320,22 @@ | ||
**Middleware config (Alternate Prod config not using precompilation, but instead compile on first access)** | ||
Note that if you use this configuration, you will **not** be able to use "hashed" filenames. | ||
app.use(express.staticCache()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
app.use(assetSmasher.middleware({ | ||
serve: { | ||
individual: false | ||
}, | ||
paths: [path.join(__dirname, 'assetDir1'), path.join(__dirname, 'assetDir2')], | ||
compress: true, | ||
prefix: '/assets', | ||
// This will make the files be served once by asset smasher | ||
// and then by the express "static" middleware thereafter. | ||
// You can then also use something like "staticCache" to cache the files if you're not | ||
// using a reverse proxy cache on the public dir | ||
outputTo: path.join(__dirname, 'public/assets') | ||
})); | ||
**View (ejs here, but could be others)** | ||
@@ -320,0 +342,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79552
1859
423