| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
vite's MPA unlike @vue/cli's pages option have a configuration in dev mode.
vite's html file need to place in project's root to have same behavior in dev and production mode, it makes your project's root dir looks chaotic.
And if you follow vite's MPA, put other file in other directory, unlike index.html, you need useless middle directory( Ex. from vite's MPA doc http://localhost:3000/nested/nested.html) to located it.
so, i write this plugin to make vite's MPA more configurable and in dev mode or production has same behavior.
this plugin use vite's configureServer Hook to intercept html request and response the html content requested from browser.
yarn add vite-plugin-virtual-html --dev # npm install vite-plugin-virtual-html -D
Add it to vite.config.js
// vite.config.js
const virtualHtml = require('vite-plugin-virtual-html')
const pages = {
index: '/src/index/index.html',
login: '/src/login/login.html',
}
module.exports = {
plugins: [virtualHtml({
pages,
indexPage: 'login'
})],
}config your project's all html/template file's path
it will be used for:
// all config
{
// 1. directly input html/template path
login1: '/src/index/index.html',
// 2. a object with template
login2: {
template: '/src/login/login.html', // if there is no data prop, the login.html must only contain HTML content
},
// 3. a object with template and data, maybe with render
login3: {
template: '/src/login1/login1.html',
data: {
users: ['a', 'b', 'c']
},
// each page can have independent render function
// render(template, data){
// return template
// }
},
// 4. config a js file path to auto-generate a html file
login4: {
entry: '/src/login/login.js', // MUST
title: 'login4',// optional, default: ''
body: '<div id="app"></div>' // optional, default: '<div id="app"></div>'
}
}
notice:
config the index page
Ex. when you open http://localhost:3000, your project's root dir has no index.html file, then browser will show 404.
now, if you set this, plugin will intercept / request, and response with page you set.
Like this: when you set indexPage to login,then you access http://localhost:3000 in browser, it will show the /login.html page.
it equals to access http://localhost:3000/login.html.
from 0.1.0 , you can use render function to render html template. i have just test in ejs, but i think other template system will(maybe) work correctly.
notice:
Customize fast-glob's pattern When set this options, it will replace default fast-glob pattern, it's default value is ['**/*.html', '!node_modules/**/*.html', '!.**/*.html']
In html file, put replacementbefore/after find
Allow plugin's user to fully customize the url, this is a function which has two param:(resolvedUrl,req)
First param: resolvedUrl is a string, it means the plugin handles from req param.
Second param : req, is a http.IncommingMessage
This function must return a string
| Back | FazBrowse Home | New Git URL |