Skip to content

Instantly share code, notes, and snippets.

@frank-dspeed
Last active November 16, 2017 20:33
Show Gist options
  • Save frank-dspeed/dfffc060b523175e39f88b66ed1779e4 to your computer and use it in GitHub Desktop.
Save frank-dspeed/dfffc060b523175e39f88b66ed1779e4 to your computer and use it in GitHub Desktop.
Basics HTML5 + WebComponents
<html><head>
<script type="text/javascript">
let ownerDocument = document.currentScript.ownerDocument
let baseUrl = ownerDocument.location.pathname.split('import.html')[0]
let base = document.createElement('base')
base.href = baseUrl
ownerDocument.head.appendChild(base)
</script>
<!-- here base gets attached -->
</head><body>
<script src="./node_modules/steal/steal.js" main="@empty" async defer></script>
</body></html>

package.json

{
  "name": "steal-element",
  "version": "0.0.1",
  "description": "StealJS Element to dedublicate Steal Loading and other optimizations",
  "main": "steal-element.js",
  "repository": "https://github.com/at-nikolaus/steal-element",
  "author": "Frank Lemanschik <[email protected]>",
  "license": "Apache-2.0",
  "dependencies": {
    "steal": "^1.6.0"
  },
  "devDependencies": {
    "steal-tools": "^1.9.2"
  }
}

import.html from import-relativ-self.html

Use

create folder steal-element cd steal-element yarn init yarn add steal create import.html

<html><head>
  <script type="text/javascript">   
    let ownerDocument = document.currentScript.ownerDocument
    let baseUrl = ownerDocument.location.pathname.split('import.html')[0]
    let base = document.createElement('base')
    base.href = baseUrl
    ownerDocument.head.appendChild(base)
  </script>
  <!-- here base gets attached -->
</head><body>
  <link rel="import" src="steal-element/import.html">
  <script>
    // Setting the base Url for this document
    let base = document.currentScript.ownerDocument.querySelector('base')
    if (base) {
      steal.config({
          baseURL: base.href+"../libs" // document.createElement('base').href
      });
    }

    steal.import(my-lib)
  </script>  
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment