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(config): transforms for index.html #793

Merged
merged 3 commits into from
Oct 26, 2020

Conversation

antfu
Copy link
Member

@antfu antfu commented Sep 10, 2020

This PR introduced a new config indexHtmlTransforms which allows plugins and vite.config.js to transform the index.html for various needs. (not sure about the naming though, feel free to leave comments)

For example, it would be useful for these plugins(probably not exist yet, just giving the context

  • vite-plugin-meta
  • vite-plugin-sitemap
  • vite-plugin-pwa
  • vite-plugin-minify
  • etc.

the following config replaces page's title to Vite Playground

// vite.config.js

export default {
  indexHtmlTransforms: [
    {
      flush: 'pre', // or 'post'
      transform({ code, isBuild }) {
        return code.replace(/<title>.*?<\/title>/, '<title>Vite Playground</title>')
      }
    }
  ]
}

flush also provides the ability to control when should the transforms apply (before Vite's processing or after)

Resolves #528, #739

Related #639, vuejs/vitepress#77 (comment)

@antfu antfu requested a review from underfin September 10, 2020 14:28
@antfu antfu mentioned this pull request Sep 21, 2020
@antfu
Copy link
Member Author

antfu commented Oct 15, 2020

@knightly-bot build this

@knightly-bot
Copy link

Nightly Build

🌒 Knightly build enabled, release every night at 00:00 UTC (skip if no change)

📦 npm package

Copy link
Member

@yyx990803 yyx990803 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some small adjustments:

  • flush -> apply
  • Defaults to apply: 'post', so the transform can directly be a function instead of always having to use an object with explicit apply timing.

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

Successfully merging this pull request may close these issues.

Provide path option and apply transform for index.html
3 participants