Skip to content

Commit

Permalink
fix: 修复vite构建时public下的html文件无法正常访问问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wanchun committed Nov 10, 2023
1 parent 5852356 commit 72dddfb
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 30 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'no-restricted-syntax': 'off',
'no-undefined': 'off',
'vue/valid-template-root': 'off',
'no-use-before-define': 'off',
},
env: {
jest: true,
Expand Down
13 changes: 12 additions & 1 deletion packages/fes-builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@
"rollup-plugin-visualizer": "^5.6.0",
"terser": "^5.16.8",
"vite": "^4.2.1",
"vite-plugin-html": "^3.2.0"
"@rollup/pluginutils": "^4.2.0",
"colorette": "^2.0.16",
"connect-history-api-fallback": "^2.0.0",
"consola": "^2.15.3",
"dotenv": "^16.0.0",
"dotenv-expand": "^8.0.2",
"ejs": "^3.1.6",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.1",
"html-minifier-terser": "^6.1.0",
"node-html-parser": "^5.3.3",
"pathe": "^0.2.0"
},
"peerDependencies": {
"@fesjs/fes": "^3.1.4",
Expand Down
15 changes: 15 additions & 0 deletions packages/fes-builder-vite/src/common/connectHistoryMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { join } from 'path';
import { pathExistsSync } from 'fs-extra';
import historyFallback from 'connect-history-api-fallback';

const proxyMiddleware = (viteConfig, params) => (req, res, next) => {
const fileName = join(viteConfig.publicDir, req.url);
if (req.url.length > 1 && req.url.startsWith('/') && pathExistsSync(fileName)) {
return next();
}

const history = historyFallback(params);
history(req, res, next);
};

export default proxyMiddleware;
2 changes: 1 addition & 1 deletion packages/fes-builder-vite/src/common/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'path';
import { existsSync } from 'fs';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { createHtmlPlugin } from 'vite-plugin-html';
import { createHtmlPlugin } from './vite-plugin-html';
import SFCConfigBlockPlugin from './SFCConfigBlockPlugin';
import getDefine from './getDefine';

Expand Down
Loading

0 comments on commit 72dddfb

Please sign in to comment.