Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

fingerpint support for requirejs #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/AssetGroupProcessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ module.exports = function(options) {
},
requirejs: function(assetGroup, callback) {
util.createDirForFileSync(assetGroup.filepath);
var mainAsset = assetGroup.createAsset(assetGroup.config.main);
var resourceName = assetGroup.config.fingerprint ? assetGroup.name : assetGroup.config.main;
var mainAsset = assetGroup.createAsset({
name: assetGroup.config.main,
url: util.routeJoin(assetGroup.config.route || "", resourceName)
});
var libAsset = assetGroup.createAsset({
name : assetGroup.config.lib,
attributes : [{
Expand Down
13 changes: 10 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,18 @@ describe('Asset Middleware in production', function() {
type: "requirejs",
dir: "js",
main: "app.js",
lib: "../lib/require.js"
lib: "../lib/require.js",
fingerprint: true,
files: [ // for fingerpint
'app.js',
'controllers/test.js'
]
}
}, middlewareConf, function(err) {
if(err) return done(err);
fs.readFile(path.join(middlewareConf.buildDir, "js", "app.js"), "utf8", function(err, content) {
var md5Hash = "5451665593271599f1f3b9544ec8eaeb";
var fileName = md5Hash+"-app";
fs.readFile(path.join(middlewareConf.buildDir, "js", fileName + ".js"), "utf8", function(err, content) {
if(err) return done(err);
assert.ok( content.length > 0 );
var res = { locals: {} };
Expand All @@ -113,7 +120,7 @@ describe('Asset Middleware in production', function() {
var html = res.locals.asset("app.js");
assert.ok( html.doesContain('<script ') );
assert.ok( html.doesContain(' src="/static/lib/require.js"') );
assert.ok( html.doesContain(' data-main="/static/js/app"') );
assert.ok( html.doesContain(' data-main="/static/js/'+fileName+'"') );
assert.ok( html.doesContain(' type="text/javascript"') );
assert.ok( html.doesContain('</script>') );
done();
Expand Down