Skip to content

runtime.basename配置能从url里自动识别吗? #6025

Answered by ejfkdev
ejfkdev asked this question in Q&A
Discussion options

You must be logged in to vote

解决了

  1. 静态资源改相对路径
    修改assetPrefix为相对路径
  output: {
    assetPrefix: './',
  }
  1. 使用自控式路由
    如果使用内置的路由,在非根目录下部署又不修改basename,页面会无限刷新
    代码放到src/App.tsx中

  2. 重命名入口,build出来就是index.html了

  source: {
    entries: {
      index: {
        entry: './src/App.tsx',
      },
    },
    disableDefaultEntries: true,
  }

完整配置:

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

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@zllkjc
Comment options

@ejfkdev
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ejfkdev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants