Skip to content

Commit

Permalink
Merge pull request #1363 from joscha/joscha/fix-extract-text-webpack-…
Browse files Browse the repository at this point in the history
…plugin-usage

fix: allow multiple assets with different types
  • Loading branch information
shilman authored Jun 28, 2017
2 parents da6bd65 + be7625a commit 768f9ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/react/src/server/iframe.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import url from 'url';
// 'preview.0d2d3d845f78399fd6d5e859daa152a9.css',
// 'static/preview.9adbb5ef965106be1cc3.bundle.js.map',
// 'preview.0d2d3d845f78399fd6d5e859daa152a9.css.map' ]
const urlsFromAssets = assets => {
export const urlsFromAssets = assets => {
if (!assets) {
return {
js: ['static/preview.bundle.js'],
Expand All @@ -26,13 +26,13 @@ const urlsFromAssets = assets => {
// Don't load the manager script in the iframe
.filter(key => key !== 'manager')
.forEach(key => {
const asset = assets[key];
if (typeof asset === 'string') {
urls[re.exec(asset)[1]].push(asset);
} else {
const assetUrl = asset.find(u => re.exec(u)[1] !== 'map');
urls[re.exec(assetUrl)[1]].push(assetUrl);
let assetList = assets[key];
if (!Array.isArray(assetList)) {
assetList = [assetList];
}
assetList.filter(assetUrl => re.exec(assetUrl)[1] !== 'map').forEach(assetUrl => {
urls[re.exec(assetUrl)[1]].push(assetUrl);
});
});

return urls;
Expand Down
21 changes: 21 additions & 0 deletions app/react/src/server/iframe.html.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { urlsFromAssets } from './iframe.html';

describe('server.urlsFromAssets', () => {
it('should return the default when there are no assets', () => {
expect(urlsFromAssets()).toEqual({
js: ['static/preview.bundle.js'],
css: [],
});
});

it('should return multiple assets', () => {
const fixture = {
manager: 'static/manager.a.bundle.js',
preview: ['static/preview.x.bundle.js', 'static/preview.y.css', 'static/preview.y.css.map'],
};
expect(urlsFromAssets(fixture)).toEqual({
js: ['static/preview.x.bundle.js'],
css: ['static/preview.y.css'],
});
});
});

0 comments on commit 768f9ff

Please sign in to comment.