Open chenyaowen123 opened 5 months ago
I am a novice programmer and my English is not very good. There might be a lot of non-standard code. If my description is not detailed enough, or if there is anything you need me to provide, please feel free to tell me at any time.😅
try configuring outDir
with absolute path:
// .vitepress/pwa/index.js
import { dirname, resolve } from "node:fs";
import { fileURLToPath } from "node:url";
const _dirname = dirname(fileURLToPath(import.meta.url));
const pwaOptions = {
outDir: resolve(_dirname, "../dist"),
...
}
Thank you for your guidance, I have succeeded. But there is a slight difference. I used the code you provided, but it prompted The requested module 'node: fs' does not provide an export named' dirname '
, so I changed it to the following method, achieving my expected effect. 😋
// .vitepress/pwa/index.js
import path from 'path';
import { fileURLToPath } from 'url';
const _dirname = path.dirname(fileURLToPath(import.meta.url));
const pwaOptions = {
outDir: path.resolve(_dirname, "../dist"),
...
}
中文版本: 在使用 @vite-pwa/vitepress 插件时,我发现了两个问题 1、其中一个是安装运行的问题。 2、文件输出的问题。 我的推测:在处理 PWA 构建输出目录 outDir 的时候,没有正确地处理 VitePress 配置中的 srcDir 设置。当指定 srcDir 为 src 文件夹时,插件默认生成的 .vitepress/dist 目录错误地出现在 src 文件夹内。这表明插件在解析输出目录时,没有根据 srcDir 的值进行相应的调整。
I found two issues when using the @ vite pwa/vitepress plugin
My configuration process
install
pwaConfig.js
.vitePress/config.mjs
Error reported during code runtime
The device I am using is MacBook,,Node v18.16.0,yarn v1.22.17。When I tried to reinstall vite plugin pwa in my project, this issue was resolved, but I am very confused about it.
Now the content of my package.json article is as follows
I tried to execute the build command
The. vitepress/dist directory appears in my src directory,I tried deleting node.modules and reinstalling them, but it didn't work.
Some necessary screenshots