Closed usercao closed 1 year ago
换一下模板路径,不要放到public目录下,这个目录会被vite当做静态目录代理。或者你就
// vite.config
{
publicDir: false
}
感谢,我就是希望把index.html
放回到public
目录下,为此几乎找遍了所有插件,只有此插件是最快速的,但是到最后还是开始报警告信息非常难受,这个改动只是个人喜好。
理解,那个信息是vite报的,不是插件报的
不会,但是会对开发造成影响,如果你目录下有文件并且需要通过根路径访问的话
你把html放出去就好了,或者重新开个目录叫做static然后配置成publicDir就好了
你给个最小复现demo吧,我周末看看
经过如下方法绕过了警告,也实现了修改入口文件
需求:
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
路由不会触发、导致以为是插件未适配,现在从日志入手已解决这个问题。
在使用本插件时一直提示警告信息,请问有什么办法可以关闭这个提示呢?我的配置如下:
如果不写
rewrites
没有警告信息,但是刷新之后会导致路由404。