Skip to content

Commit 5ed0f62

Browse files
ykhandors0ph1e
authored andcommitted
Enable filenameGenerator byType to read js files by mime (#291)
* Enable fileGenerator byType to read Javscript files by mimeType. Currently code only enables CSS and HTML files by mimeType. * Remove redundant .min.js extension and add unit test for Javascript byType FileNameGenerator
1 parent 798a0f0 commit 5ed0f62

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

lib/config/resource-ext-by-type.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ var defaultExtensions = {};
44
// should contain same data as ./resource-type-by-ext
55
defaultExtensions[types.html] = [ '.html', '.htm' ];
66
defaultExtensions[types.css] = [ '.css' ];
7+
defaultExtensions[types.js] = [ '.js' ];
78

89
module.exports = defaultExtensions;

lib/config/resource-type-by-ext.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ var types = require('./resource-types');
44
module.exports = {
55
'.html': types.html,
66
'.htm': types.html,
7-
'.css': types.css
7+
'.css': types.css,
8+
'.js': types.js
89
};

lib/config/resource-type-by-mime.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ var types = require('./resource-types');
22

33
module.exports = {
44
'text/html': types.html,
5-
'text/css': types.css
5+
'text/css': types.css,
6+
'text/javascript': types.js
67
};

lib/config/resource-types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var types = {
22
css: 'css',
3-
html: 'html'
3+
html: 'html',
4+
js: 'js'
45
};
56

67
module.exports = types;

test/unit/filename-generator/by-type-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ describe('FilenameGenerator: byType', function() {
3838
filename.should.equalFileSystemPath('css.css');
3939
});
4040

41+
it('should add missed extensions for js resources', function () {
42+
var r = new Resource('http://example.com/js', '');
43+
r.getType = sinon.stub().returns('js');
44+
var filename = byTypeFilenameGenerator(r, {}, []);
45+
filename.should.equalFileSystemPath('js.js');
46+
});
47+
4148
it('should not add missed extensions for other resources', function () {
4249
var r = new Resource('http://1.gravatar.com/avatar/4d63e4a045c7ff22accc33dc08442f86?s=140&d=%2Fwp-content%2Fuploads%2F2015%2F05%2FGood-JOb-150x150.jpg&r=g', '');
4350
r.getType = sinon.stub().returns('home');

0 commit comments

Comments
 (0)