diff --git a/src/transforms/posthtml.js b/src/transforms/posthtml.js
index 1ac294085c2..66b7015bac4 100644
--- a/src/transforms/posthtml.js
+++ b/src/transforms/posthtml.js
@@ -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;
}
diff --git a/test/html.js b/test/html.js
index ca9a65e466b..16cefe46877 100644
--- a/test/html.js
+++ b/test/html.js
@@ -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');