vbenjs / vite-plugin-html

A vite plugin for processing html. It is developed based on lodash template
MIT License
554 stars 92 forks source link

Injecting link tags and script tags with import doesn't work #110

Open baermathias opened 1 year ago

baermathias commented 1 year ago

If the following is your config:

inject: {
  data: {
    injectParagraphTag: `<p>this is a paragraph</p>`,
    injectScriptTag: `<script type="module">
        const origin = window.location.origin;
        import(origin + '/modules/components@1.0.0/dist/index.umd.js')
      </script>`,
    injectLinkTag: `<link rel="stylesheet" href="/../modules/components/css/fonts.css" />`,
    injectCustomElement: `<custom-link-tag rel="stylesheet" href="/../modules/components/css/fonts.css" />`,
  },
}

And these are the ejs tags in your index.html:

  <%- injectParagraphTag %>
  <%- injectScriptTag %>
  <%- injectLinkTag %>
  <%- injectCustomElement %>

Then this will be the result:

  <p>this is a paragraph</p>

  <custom-link-tag rel="stylesheet" href="/../modules/components/css/fonts.css" />