fix(org/vite): 修正成员排行跨页名次与配色,拦截开发服务的 .npmrc 请求
This commit is contained in:
@@ -16,6 +16,7 @@ const DEV_PROXY_TARGET = 'http://134.175.227.134:13000';
|
||||
*/
|
||||
const JSX_IN_JS_RE = /src\/.*\.js$/;
|
||||
const REACT_RUNTIME_RE = /\/node_modules\/(?:react|react-dom|scheduler)\//;
|
||||
const NPM_CONFIG_PATH_RE = /(?:^|[\\/])\.npmrc[. ]*(?:[\\/]|$)/i;
|
||||
|
||||
/**
|
||||
* 让 JSX_IN_JS_RE 命中的 .js 按 JSX 语法解析。
|
||||
@@ -59,6 +60,29 @@ function disableDevImportGlob() {
|
||||
};
|
||||
}
|
||||
|
||||
function blockNpmConfigRequests() {
|
||||
return {
|
||||
name: 'block-npm-config-requests',
|
||||
configureServer(server) {
|
||||
server.middlewares.use((request, response, next) => {
|
||||
let pathname;
|
||||
try {
|
||||
pathname = decodeURIComponent(
|
||||
(request.url ?? '').split(/[?#]/, 1)[0],
|
||||
);
|
||||
} catch {
|
||||
return next();
|
||||
}
|
||||
if (!NPM_CONFIG_PATH_RE.test(pathname)) return next();
|
||||
|
||||
// Stop before Vite tries to load the file or broadcasts an HMR error.
|
||||
response.statusCode = 404;
|
||||
response.end();
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 向 index.html 注入统计脚本。
|
||||
*
|
||||
@@ -123,6 +147,7 @@ export default defineConfig(({ mode, command }) => {
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
blockNpmConfigRequests(),
|
||||
disableDevImportGlob(),
|
||||
jsxInJsPlugin(),
|
||||
react(),
|
||||
@@ -172,6 +197,10 @@ export default defineConfig(({ mode, command }) => {
|
||||
// 监听局域网接口,供本机、后端及测试人员联调。
|
||||
host: '0.0.0.0',
|
||||
port: 5174,
|
||||
fs: {
|
||||
// Setting deny replaces the Vite defaults.
|
||||
deny: ['.env', '.env.*', '*.{crt,pem}', '**/.git/**', '.npmrc'],
|
||||
},
|
||||
warmup: {
|
||||
clientFiles: [
|
||||
'./src/index.jsx',
|
||||
|
||||
Reference in New Issue
Block a user