diff --git a/package.json b/package.json index 813706c8bee..f6ef0405126 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "node-sass": "^4.7.2", "nyc": "^11.1.0", "postcss-modules": "^1.1.0", + "posthtml-extend": "^0.2.1", "posthtml-include": "^1.1.0", "prettier": "^1.13.0", "pug": "^2.0.3", diff --git a/src/assets/HTMLAsset.js b/src/assets/HTMLAsset.js index 0645afe53a7..2dd0f56de65 100644 --- a/src/assets/HTMLAsset.js +++ b/src/assets/HTMLAsset.js @@ -112,7 +112,20 @@ class HTMLAsset extends Asset { } collectDependencies() { - this.ast.walk(node => { + let {ast} = this; + + // Add bundled dependencies from plugins like posthtml-extend or posthtml-include, if any + if (ast.messages) { + ast.messages.forEach(message => { + if (message.type === 'dependency') { + this.addDependency(message.file, { + includedInParent: true + }); + } + }); + } + + ast.walk(node => { if (node.attrs) { if (node.tag === 'meta') { if ( diff --git a/src/transforms/posthtml.js b/src/transforms/posthtml.js index f12219bc7eb..e65aee23939 100644 --- a/src/transforms/posthtml.js +++ b/src/transforms/posthtml.js @@ -38,6 +38,8 @@ async function getConfig(asset) { config = config || {}; const plugins = config.plugins; if (typeof plugins === 'object') { + // This is deprecated in favor of result messages but kept for compatibility + // See https://github.com/posthtml/posthtml-include/blob/e4f2a57c2e52ff721eed747b65eddf7d7a1451e3/index.js#L18-L26 const depConfig = { addDependencyTo: { addDependency: name => diff --git a/test/html.js b/test/html.js index cf4313eab93..a88a68d3853 100644 --- a/test/html.js +++ b/test/html.js @@ -116,6 +116,19 @@ describe('html', function() { assert(asset.dependencies.get(other).includedInParent); }); + it('should add dependencies referenced by plugins', async () => { + const b = await bundle( + __dirname + '/integration/posthtml-plugin-deps/index.html' + ); + const asset = b.assets.values().next().value; + const other = path.join( + __dirname, + '/integration/posthtml-plugin-deps/base.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'); diff --git a/test/integration/posthtml-plugin-deps/base.html b/test/integration/posthtml-plugin-deps/base.html new file mode 100644 index 00000000000..8e2a53b1d43 --- /dev/null +++ b/test/integration/posthtml-plugin-deps/base.html @@ -0,0 +1,8 @@ + +
+Hello
+