vite-plugin-html-resolve-alias
v2.0.0
Published
A vite plugin that can use aliases in html content.
Downloads
327
Readme
vite-plugin-html-resolve-alias
Install
npm install vite-plugin-html-resolve-alias -D
yarn add vite-plugin-html-resolve-alias -D
pnpm install vite-plugin-html-resolve-alias -D
Usage
Add the plugin to your Vite config as follows:
import path from 'node:path'
import { defineConfig } from 'vite'
import viteHtmlResolveAlias from 'vite-plugin-html-resolve-alias'
export default defineConfig({
resolve: {
// https://vitejs.cn/config/#resolve-alias
alias: {
'@': path.resolve(__dirname, 'src/')
}
},
plugins: [
viteHtmlResolveAlias(/* Options */)
]
})
Next, you can use aliases in HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="@/main.css">
</head>
<body>
<img src="@/foo.png" />
<script src="@/main.js"></script>
</body>
</html>
Options
tags
Specify the tag and tag attribute name to be resolved.
type Tags = Record<string, string[]>
Default
const defaultTags: Tags = {
video: ['src', 'poster'],
source: ['src'],
img: ['src'],
image: ['xlink:href', 'href'],
use: ['xlink:href', 'href'],
link: ['href'],
script: ['src']
}