vitejs / vite-plugin-vue2

Vite plugin for Vue 2.7
MIT License
543 stars 46 forks source link

Unrecognised top-level tags (eg. `<docs>`) are parsed as javascript by default #86

Open baffalop opened 1 year ago

baffalop commented 1 year ago

I'm migrating a large Vue app to Vite. One issue I ran into was with <docs> tags that a few of our SFCs have, which contain documentation in markdown to be read by Storybook. These tags exist at the top level, ie. alongside <template>, <script> and <style>. I would expect them to be ignored. Instead the compiler appears to assume that these tags contain javascript, and as a result Vite (or sometimes the browser) is throwing parse errors.

This issue has previously been mentioned in this discussion, and I was able to solve it following the suggestion in that thread to create a custom Vite plugin to ignore the contents of <docs>, but I believe it constitutes a bug/unexpected behaviour. Why should the contents of a non-<script> tag be run as javascript? I can understand that, as per "Example for transforming custom blocks" in the docs, there is the flexibility to treat additional tags in special ways and I'm sure this is useful, but I don't think "execute as javascript" is a safe default.