trapcodeio / vite-plugin-ejs

Vite: Use Ejs in your entypoints i.e index.html
https://stackblitz.com/edit/vite-plugin-ejs
66 stars 5 forks source link

link tags and script tags with import don't work #10

Closed baermathias closed 1 year ago

baermathias commented 1 year ago

If the following is your config:

const ejsPlugin = ViteEjsPlugin({
  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" />
trapcodeio commented 1 year ago

Is there any specific reason why you want to inject scripts as variables? Won't a partial work better?

trapcodeio commented 1 year ago

Due to no response on this.. i will close this issue.