Skip to content

Instantly share code, notes, and snippets.

@jmaicher
Last active February 5, 2017 14:32
Show Gist options
  • Save jmaicher/f696b510008adadd94d2b7fbb35c8966 to your computer and use it in GitHub Desktop.
Save jmaicher/f696b510008adadd94d2b7fbb35c8966 to your computer and use it in GitHub Desktop.
Express fragment dependencies with tailor
<html>
<head>
<!-- ... -->
<script>
// stub implementation in case the shell fragment fails to resolve
define("shell", function() { return stub; });
</script>
</head>
<body>
<fragment src="shell.example.com"></fragment>
<fragment src="foo.example.com"></fragment>
</body>
</html>
<div id="shell">
<header><!-- ... --></header>
<aside><!-- ... --></aside>
</div>
<script>
require.undef('shell');
// Note that the bundle url is dynamically injected from the asset manifest
define("shell", ["/shell.bundle.js"], function(s) { return s.api });
</script>
var api;
// will be called by tailor on pipe.end
export default (element) => {
let view = new ShellView(element);
api = new ShellApi(view);
}
export { api };
// marked as external in webpack config
const shell = require('shell');
// will be called by tailor on pipe.end
export default (element) => {
console.log(shell); // => ShellApi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment