Skip to content

Commit

Permalink
Add dependencies referenced by posthtml-include (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanyow authored and devongovett committed May 22, 2018
1 parent 46fb97a commit 3988ffc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/transforms/posthtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ async function getConfig(asset) {
}

config = Object.assign({}, config);
config.plugins = await loadPlugins(config.plugins, asset.name);
const plugins = config.plugins;
if (typeof plugins === 'object') {
const depConfig = {
addDependencyTo: {
addDependency: name =>
asset.addDependency(name, {includedInParent: true})
}
};
Object.keys(plugins).forEach(p => Object.assign(plugins[p], depConfig));
}
config.plugins = await loadPlugins(plugins, asset.name);
config.skipParse = true;
return config;
}
10 changes: 10 additions & 0 deletions test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ describe('html', function() {
});
});

it('should add dependencies referenced by posthtml-include', async () => {
const b = await bundle(
__dirname + '/integration/posthtml-assets/index.html'
);
const asset = b.assets.values().next().value;
const other = __dirname + '/integration/posthtml-assets/other.html';
assert(asset.dependencies.has(other));
assert(asset.dependencies.get(other).includedInParent);
});

it('should insert sibling CSS bundles for JS files in the HEAD', async function() {
let b = await bundle(__dirname + '/integration/html-css/index.html');

Expand Down

0 comments on commit 3988ffc

Please sign in to comment.