umijs / dumi

📖 Static Site Generator for component library development
https://d.umijs.org
MIT License
3.58k stars 1.18k forks source link

bug: 非根目录打包后白屏 #1852

Closed czb128abc closed 1 year ago

czb128abc commented 1 year ago

Versions

Steps to reproduce

配置文件:

import { defineConfig } from 'dumi';

const isProd = process.env.NODE_ENV === 'production';

export default defineConfig({
  mfsu: isProd ? false : {},
  base:isProd ? '/docs-dist' : '/',
  publicPath: isProd ? '/docs-dist/' : '/',
  runtimePublicPath: isProd ? {}: false,
  history: { type: 'hash' },
  cacheDirectoryPath:`./.dumi/${isProd?'tmp-production':'tmp'}-cache`,
  outputPath: 'docs-dist',
  themeConfig: {
    name: 'pro-crud-page',
  },
  devtool: !isProd ? 'cheap-module-source-map' : false,
});

打包后输出html

<!DOCTYPE html><html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/docs-dist/umi.7ab43a5e.css">
</head>
<body>
<div id="root"></div>
<script src="/docs-dist/umi.4025772a.js"></script>

</body></html>
image

打包文件截图

image

What is Expected?

What is actually happening?

czb128abc commented 1 year ago

打包后文件列表如下:

docs-dist/~demos
docs-dist/curd-page
docs-dist/guide
docs-dist/299.3a02b37c.async.js
docs-dist/299.f9797d42.chunk.css
docs-dist/404.html
docs-dist/476.0da23ec7.async.js
docs-dist/607.0e7d3e02.async.js
docs-dist/629.4991cb48.async.js
docs-dist/demos.4dc37f2b.async.js
docs-dist/docs__curd-page__demo.md.16eb4f76.async.js
docs-dist/docs__curd-page__demo.md.778c6473.chunk.css
docs-dist/docs__guide.md.778c6473.chunk.css
docs-dist/docs__guide.md.ce9d060e.async.js
docs-dist/docs__index.md.778c6473.chunk.css
docs-dist/docs__index.md.6950a73c.async.js
docs-dist/dumi__pages__404.0c45fd57.async.js
docs-dist/dumi__pages__404.8b85f2d9.chunk.css
docs-dist/dumi__pages__Demo.455f9dbe.async.js
docs-dist/dumi__pages__Demo.578aa5c0.chunk.css
docs-dist/dumi__theme__ContextWrapper.d3e2dccf.async.js
docs-dist/dumi__theme__layouts__DocLayout.ec323db5.async.js
docs-dist/index.html
docs-dist/umi.7ab43a5e.css
docs-dist/umi.4025772a.js
czb128abc commented 1 year ago

代码地址: https://gitee.com/zbchen/pro-crud-page

PeachScript commented 1 year ago

你配的是 hash 路由,应当使用 /#/{base} 的形式访问而不是 /{base}

另外 dumi 2 对 hash 路由的支持不完整,锚点之类的会跳转异常,建议用默认的 browser 路由