feat: Add VITE_DEV_PROXY configuration for npm registry API proxy
All checks were successful
CI / cache-and-install (push) Successful in 2m6s

This commit is contained in:
严浩
2024-09-18 13:35:17 +08:00
parent ee3d5186ff
commit 5422f68b45
5 changed files with 15 additions and 2 deletions

View File

@ -1,3 +1,4 @@
VITE_BUILD_TIME=DEV
VITE_BUILD_COMMIT=DEV
VITE_BASE=/
VITE_DEV_PROXY=[["/npm-registry-api","https://npm-cf-proxy.oo1.dev"]]

View File

@ -2,7 +2,7 @@
// https://vue-macros.dev/zh-CN/features/reactivity-transform.html
let count = $ref(0);
console.log(count);
// console.log(count);
function increment() {
count++;

View File

@ -25,6 +25,11 @@ const FComponent: FunctionalComponent<{ prop: string }> = (props, context) => (
</div>
</>
);
/* fetch('https://jsonplaceholder.typicode.com/posts/1')
.then((response) => response.json())
.then((json) => console.log(json)); */
fetch('/npm-registry-api/@vue%2Fbabel-plugin-jsx');
</script>
<template>

View File

@ -1,3 +1,6 @@
{
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" },
{ "source": "/npm-registry-api/(.*)", "destination": "https://npm-cf-proxy.oo1.dev/$1" }
]
}

View File

@ -16,6 +16,7 @@ import Markdown from 'unplugin-vue-markdown/vite';
import { getPascalCaseRouteName, VueRouterAutoImports } from 'unplugin-vue-router';
import VueRouter from 'unplugin-vue-router/vite';
import { createSplitChunkOutput } from 'utils4u/rollup';
import { createViteProxy } from 'utils4u/vite';
import { defineConfig, loadEnv, PluginOption } from 'vite';
import cdnImport from 'vite-plugin-cdn-import';
import vueDevTools from 'vite-plugin-vue-devtools';
@ -37,6 +38,9 @@ export default defineConfig(({ mode, command }) => {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
proxy: createViteProxy(),
},
build: {
sourcemap: mode !== 'production' || env.VITE_SOURCE_MAP === 'true',
rollupOptions: {