Skip to content

Commit 3988ffc

Browse files
jdanyowdevongovett
authored andcommitted
Add dependencies referenced by posthtml-include (#1355)
1 parent 46fb97a commit 3988ffc

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/transforms/posthtml.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ async function getConfig(asset) {
2424
}
2525

2626
config = Object.assign({}, config);
27-
config.plugins = await loadPlugins(config.plugins, asset.name);
27+
const plugins = config.plugins;
28+
if (typeof plugins === 'object') {
29+
const depConfig = {
30+
addDependencyTo: {
31+
addDependency: name =>
32+
asset.addDependency(name, {includedInParent: true})
33+
}
34+
};
35+
Object.keys(plugins).forEach(p => Object.assign(plugins[p], depConfig));
36+
}
37+
config.plugins = await loadPlugins(plugins, asset.name);
2838
config.skipParse = true;
2939
return config;
3040
}

test/html.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ describe('html', function() {
102102
});
103103
});
104104

105+
it('should add dependencies referenced by posthtml-include', async () => {
106+
const b = await bundle(
107+
__dirname + '/integration/posthtml-assets/index.html'
108+
);
109+
const asset = b.assets.values().next().value;
110+
const other = __dirname + '/integration/posthtml-assets/other.html';
111+
assert(asset.dependencies.has(other));
112+
assert(asset.dependencies.get(other).includedInParent);
113+
});
114+
105115
it('should insert sibling CSS bundles for JS files in the HEAD', async function() {
106116
let b = await bundle(__dirname + '/integration/html-css/index.html');
107117

0 commit comments

Comments
 (0)