Skip to content

[Enhancement] Improve bundler config #795

@ptandler

Description

@ptandler

I started to migrate my homepage from VuePress 1 to 2 and also used this opportunity to give Vite a try.

With VuePress 1 and web pack, I used the vue-svg-loader plugin to allow inline SVG. I'm stuck to port this to VuePress 2 and Vite.

I found vite-svg-loader which looks pretty comparable. But I've got no idea how to use it.

In the documentation I read that one can add custom Vite config via viteOptions:

const svgLoader = require('vite-svg-loader')
// ...
module.exports = {
// ...
  bundlerConfig: {
    viteOptions: {
      plugins: [svgLoader()]
    }
  },
// ...
}

and within a custom Vue component I do:
'm stuck

<template>
    <ComponentLogo/>
</template>
<script>
import logo from "./stack-overflow-logo.svg?inline"

export default {
    name: "name",
    props: {
// ...
    },
    components: {ComponentLogo: logo},
//...
  }
</script>

But I get an error:

Uncaught (in promise) DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('.../global-components/Social/stack-overflow-logo.svg?inline') is not a valid name.
    at createElement

I interpret this that the imported SVG is treated as HTML or JS, but not SVG. Correct?

Coming back from this specific case to my general point: I really would appreciate to get a better explanation, and ideally also some complete and working examples of how to use Vite options and plugins. Thanks! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions