benjycui / bisheng

Transform Markdown(and other static files with transformers) into a SPA website using React.
MIT License
2.9k stars 419 forks source link

构建部署后出现 404 页面 MIME 错误 #197

Closed nitta-honoka closed 5 years ago

nitta-honoka commented 5 years ago

bisheng 版本:0.26.0

现象: 完成 bisheng build 及部署后,访问带二级路由的页面时会额外引用到 404 页面,然后报 MIME 错误

期望现象: 正常访问二级路由页面

错误截图: image image

配置文件:

module.exports = {
  hash: true,
  source: {
    components: './components',
    docs: './docs',
  },
  theme: './site/theme',
  htmlTemplate: './site/theme/static/template.html',
  port: 8002,
  themeConfig: {
    categoryOrder: {
      开放组件: 3000,
      通用组件: 5000,
      业务组件: 10000,
    },
    typeOrder: {
      营销: 0,
      内容业务: 10,
      LifeApp: 100,
    },
  },
  webpackConfig(config) {
    console.log(resolve.sync('antd'))

    config.externals = {
      react: 'React',
      'react-dom': 'ReactDOM',
      'react-router-dom': 'ReactRouterDOM',
      clipbord: 'Clipboard',
    }

    config.babel.plugins.push(
      [
        require.resolve('babel-plugin-transform-runtime'),
        {
          polyfill: false,
          regenerator: false,
        },
      ],
      [
        'babel-plugin-import',
        {
          libraryName: 'antd',
          libraryDirectory: 'lib',
          style: true,
        },
      ],
    )

    return config
  },

  htmlTemplateExtraData: {
    isDev,
  },

  root: '/',
}
module.exports = {
  lazyLoad(nodePath, nodeValue) {
    if (typeof nodeValue === 'string') {
      return true;
    }

    return nodePath.endsWith('/demo');
  },
  pick: {
    components(markdownData) {
      const { filename } = markdownData.meta;
      if (
        !/^components/.test(filename) ||
        /[/\\]demo$/.test(path.dirname(filename))
      ) {
        return;
      }

      return {
        meta: markdownData.meta,
      };
    },
    'docs/dev': pickerGenerator('dev'),
  },
  plugins: [
    'bisheng-plugin-description',
    'bisheng-plugin-toc?maxDepth=2&keepElem',
    'bisheng-plugin-antd',
    'bisheng-plugin-react?lang=__react',
  ],
  routes: {
    path: '/',
    component: './template/Layout/index',
    indexRoute: { component: homeTmpl },
    childRoutes: [
      {
        path: 'index',
        component: homeTmpl,
      },
      {
        path: '/docs/:type/:children',
        dataPath: '/:type/:children',
        component: contentTmpl,
      },
      {
        path: '/components/:children',
        dataPath: '/:children',
        component: contentTmpl,
      },
    ],
  },
};