Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add function type for options.injectStyle #855

Merged
merged 1 commit into from Mar 19, 2023

Conversation

await-ovo
Copy link
Contributor

Support setting options.injectStyle as a function that returns JS code to add CSS in a custom way, like rollup-plugin-postcss.

This can be used in some cases such as when adding styles to shadowRoot:

export defineConfig({
   injectStyle: (css) => {
    return `
        var setStyle = function() {
          setTimeout(() => {
            try {
              var style = document.createElement('style');
              style.type = 'text/css';
              style.innerHTML = ${css};
              var root = document.getElementsByTagName('${tag}')[0].shadowRoot;
              root.insertBefore(style);
            } catch {
              setStyle()
            }
          },1000)
        };
        setStyle();
      `;
  },
})

@codesandbox
Copy link

codesandbox bot commented Mar 10, 2023

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@vercel
Copy link

vercel bot commented Mar 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
tsup ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 10, 2023 at 10:05AM (UTC)

@egoist egoist merged commit 01169b3 into egoist:dev Mar 19, 2023
8 checks passed
@github-actions
Copy link

🎉 This PR is included in version 6.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants