提交 c3151d37 编写于 作者: dsyuan001's avatar dsyuan001

public html

上级 b78e063a
import seoPrerender from './render' import seoPrerender from './render'
import childProcess from 'child_process' import childProcess from 'child_process'
import path from 'path'
interface Config { interface Config {
puppeteer?: any // puppeteer一些配置 puppeteer?: any // puppeteer一些配置
routes: string[] // 需要生成的路由地址 routes?: string[] // 需要生成的路由地址
removeStyle?: boolean // 启用vite preview会自带有些样式,默认下移除 removeStyle?: boolean // 启用vite preview会自带有些样式,默认下移除
callback?: Function callback?: Function
htmlRoutes?: string[] // 处理public目录下的html文件
} }
const prerender = (config: Config) => { const prerender = (config: Config) => {
...@@ -26,6 +28,23 @@ const prerender = (config: Config) => { ...@@ -26,6 +28,23 @@ const prerender = (config: Config) => {
buildEnd() { buildEnd() {
//console.log('buildEnd') //console.log('buildEnd')
}, },
configureServer(server) {
const {watcher} = server
if (config.htmlRoutes?.length) {
// 监听 public 目录下的 HTML 文件更改
watcher.on('change', (filePath) => {
const publicRoot = path.join(server.config.root, '/public')
const relativePath = path.relative(publicRoot, filePath)
console.log('relativePath', relativePath)
/*if (filePath.startsWith(server.config.root + '/public/') && filePath.endsWith('.html')) {
console.log(`Detected change in HTML file: ${filePath}`);
// 在此处进行你的处理逻辑
// 可以读取文件内容、替换内容、编译等操作
}*/
})
}
},
closeBundle() { closeBundle() {
if (!config?.routes?.length) { if (!config?.routes?.length) {
console.log('路由地址为空,请配置需预渲染的routes') console.log('路由地址为空,请配置需预渲染的routes')
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
this is contact page ,transform 123?
<p>1234567891011</p>
</body>
</html>
body{margin: 0;padding: 0;font-size: 14px;}
import {createApp} from 'vue' import {createApp} from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import './assets/style.css'
createApp(App).use(router).mount('#app') createApp(App).use(router).mount('#app')
<template> <template>
<div>this about page</div> <div class="about">this about page</div>
</template> </template>
<style scoped> <style>
.about{color: red;font-size: 16px;}
</style> </style>
<template> <template>
<div> <div class="index">
this is test page this is test page
</div> </div>
</template> </template>
<script setup> <script setup>
</script> </script>
<style>
.index{color: antiquewhite}
</style>
...@@ -7,6 +7,9 @@ import seoPrerender from './packages/src' ...@@ -7,6 +7,9 @@ import seoPrerender from './packages/src'
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
vue(), vue(),
seoPrerender({routes: ['/about']}) seoPrerender({
routes: ['/about'],
htmlRoutes: ['/contact/index.html']
})
] ]
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册