Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dsyuan001
vite-plugin-seo-prerender
提交
c3151d37
V
vite-plugin-seo-prerender
项目概览
dsyuan001
/
vite-plugin-seo-prerender
2023-09-07 01:23:05同步失败
通知
20
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vite-plugin-seo-prerender
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c3151d37
编写于
6月 30, 2023
作者:
dsyuan001
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
public html
上级
b78e063a
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
44 addition
and
6 deletion
+44
-6
packages/src/index.ts
packages/src/index.ts
+20
-1
public/contact/index.html
public/contact/index.html
+11
-0
src/assets/style.css
src/assets/style.css
+1
-0
src/main.ts
src/main.ts
+1
-0
src/views/about/index.vue
src/views/about/index.vue
+3
-3
src/views/test.vue
src/views/test.vue
+4
-1
vite.config.ts
vite.config.ts
+4
-1
未找到文件。
packages/src/index.ts
浏览文件 @
c3151d37
import
seoPrerender
from
'
./render
'
import
childProcess
from
'
child_process
'
import
path
from
'
path
'
interface
Config
{
puppeteer
?:
any
// puppeteer一些配置
routes
:
string
[]
// 需要生成的路由地址
routes
?
:
string
[]
// 需要生成的路由地址
removeStyle
?:
boolean
// 启用vite preview会自带有些样式,默认下移除
callback
?:
Function
htmlRoutes
?:
string
[]
// 处理public目录下的html文件
}
const
prerender
=
(
config
:
Config
)
=>
{
...
...
@@ -26,6 +28,23 @@ const prerender = (config: Config) => {
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
()
{
if
(
!
config
?.
routes
?.
length
)
{
console
.
log
(
'
路由地址为空,请配置需预渲染的routes
'
)
...
...
public/contact/index.html
0 → 100644
浏览文件 @
c3151d37
<!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>
src/assets/style.css
0 → 100644
浏览文件 @
c3151d37
body
{
margin
:
0
;
padding
:
0
;
font-size
:
14px
;}
src/main.ts
浏览文件 @
c3151d37
import
{
createApp
}
from
'
vue
'
import
App
from
'
./App.vue
'
import
router
from
'
./router
'
import
'
./assets/style.css
'
createApp
(
App
).
use
(
router
).
mount
(
'
#app
'
)
src/views/about/index.vue
浏览文件 @
c3151d37
<
template
>
<div>
this about page
</div>
<div
class=
"about"
>
this about page
</div>
</
template
>
<
style
scoped
>
<
style
>
.about
{
color
:
red
;
font-size
:
16px
;}
</
style
>
src/views/test.vue
浏览文件 @
c3151d37
<
template
>
<div>
<div
class=
"index"
>
this is test page
</div>
</
template
>
<
script
setup
>
</
script
>
<
style
>
.index
{
color
:
antiquewhite
}
</
style
>
vite.config.ts
浏览文件 @
c3151d37
...
...
@@ -7,6 +7,9 @@ import seoPrerender from './packages/src'
export
default
defineConfig
({
plugins
:
[
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录