emosheeep / vite-plugin-virtual-mpa

Out-of-box MPA plugin for Vite, generate multiple entries using only one template.
https://stackblitz.com/~/github.com/emosheeep/vite-plugin-virtual-mpa
MIT License
116 stars 15 forks source link

禁止插件警告信息 #28

Closed usercao closed 1 year ago

usercao commented 1 year ago

image

在使用本插件时一直提示警告信息,请问有什么办法可以关闭这个提示呢?我的配置如下:

    createMpaPlugin({
      verbose: false,
      template: 'public/index.html',
      pages: [{ name: 'index', filename: 'index.html' }],
      rewrites: [{ to: () => normalizePath('/public/index.html') }],
    }),

如果不写rewrites没有警告信息,但是刷新之后会导致路由404。

emosheeep commented 1 year ago

换一下模板路径,不要放到public目录下,这个目录会被vite当做静态目录代理。或者你就

// vite.config
{
  publicDir: false
}
usercao commented 1 year ago

感谢,我就是希望把index.html放回到public目录下,为此几乎找遍了所有插件,只有此插件是最快速的,但是到最后还是开始报警告信息非常难受,这个改动只是个人喜好。

emosheeep commented 1 year ago

理解,那个信息是vite报的,不是插件报的

emosheeep commented 1 year ago

不会,但是会对开发造成影响,如果你目录下有文件并且需要通过根路径访问的话

emosheeep commented 1 year ago

你把html放出去就好了,或者重新开个目录叫做static然后配置成publicDir就好了

emosheeep commented 1 year ago

你给个最小复现demo吧,我周末看看

usercao commented 1 year ago

经过如下方法绕过了警告,也实现了修改入口文件需求:

import { defineConfig, Logger, createLogger } from 'vite';

const customLogger = (): Logger => {
  const logger = createLogger();
  return {
    ...logger,
    warn: (message, options) => {
      const regexp = new RegExp('files in the public directory are served at the root path.', 'g');
      if (regexp.test(message)) return;
      logger.info(message, options);
    },
  };
};

export default defineConfig({
  customLogger: customLogger(),
  plugins: [
    createMpaPlugin({
      verbose: false,
      template: 'public/index.html',
      pages: [{ name: 'index', filename: 'index.html' }],
      rewrites: [{ from: /.*/, to: '/public/index.html' }],
    }),
  ],
});

经过测试需要rewrites的问题其实一直存在,因为最开始的测试项目使用了hash路由不会触发、导致以为是插件未适配,现在从日志入手已解决这个问题。