-
ssg静态单页,托管到云端部署,访问路径前缀是跟随部署项目的hash变化的,不方便指定固定前缀的basename |
Beta Was this translation helpful? Give feedback.
Answered by
ejfkdev
Jul 31, 2024
Replies: 2 comments 2 replies
-
还有启用了bff有后端api的情况,也需要可以自动适应前缀,不知道有没有办法实现 |
Beta Was this translation helpful? Give feedback.
2 replies
-
解决了
完整配置: import { appTools, defineConfig } from '@modern-js/app-tools';
import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
import { ssgPlugin } from '@modern-js/plugin-ssg';
// https://modernjs.dev/en/configure/app/usage
export default defineConfig({
source: {
entries: {
index: {
entry: './src/App.tsx',
},
},
disableDefaultEntries: true,
},
html: {
disableHtmlFolder: true,
},
runtime: {
router: false,
},
output: {
distPath: {
html: '',
},
assetPrefix: './',
ssg: true,
},
plugins: [
appTools({
bundler: 'experimental-rspack',
}),
tailwindcssPlugin(),
ssgPlugin(),
],
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ejfkdev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解决了
修改assetPrefix为相对路径
使用自控式路由
如果使用内置的路由,在非根目录下部署又不修改basename,页面会无限刷新
代码放到src/App.tsx中
重命名入口,build出来就是index.html了
完整配置: