Skip to content

Commit

Permalink
Transform HTML prior to collecting dependencies (#483)
Browse files Browse the repository at this point in the history
* Failing test case for assets in posthtml include

The same issue exists for posthtml-extend.

* Transform HTML prior to collecting dependencies

Until HTML is transformed, some dependencies may not be visible.

* Remove post collection HTML transform

As recommended by @devongovett and @shawwn in Slack
  • Loading branch information
ipmb authored and devongovett committed Jan 4, 2018
1 parent e09575d commit 2fbba62
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class HTMLAsset extends Asset {
});
}

async transform() {
async pretransform() {
await posthtmlTransform(this);
}

Expand Down
16 changes: 16 additions & 0 deletions test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ describe('html', function() {
assert(html.includes('<h1>Other page</h1>'));
});

it('should find assets inside posthtml', async function() {
let b = await bundle(__dirname + '/integration/posthtml-assets/index.html');

assertBundleTree(b, {
name: 'index.html',
assets: ['index.html'],
childBundles: [
{
type: 'js',
assets: ['index.js'],
childBundles: []
}
]
});
});

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
7 changes: 7 additions & 0 deletions test/integration/posthtml-assets/.posthtmlrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
plugins: {
"posthtml-include": {
root: __dirname
}
}
};
6 changes: 6 additions & 0 deletions test/integration/posthtml-assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<html>
<body>
<include src="other.html"></include>
</body>
</html>
1 change: 1 addition & 0 deletions test/integration/posthtml-assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.alert("Hello world!");
2 changes: 2 additions & 0 deletions test/integration/posthtml-assets/other.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Other page</h1>
<script src="index.js"></script>

0 comments on commit 2fbba62

Please sign in to comment.