feat(config): 添加 VITE_CLOUDFLARE_SERVER_ENABLED 环境变量支持
This commit is contained in:
1
.env
1
.env
@@ -7,3 +7,4 @@ VITE_APP_BUILD_TIME=
|
||||
VITE_ENABLE_VUE_DEVTOOLS=true
|
||||
VITE_MENU_SHOW_DEMOS=true
|
||||
VITE_MENU_SHOW_ORDER=true
|
||||
VITE_CLOUDFLARE_SERVER_ENABLED=true
|
||||
@@ -5,6 +5,7 @@ import './styles/index.ts';
|
||||
|
||||
import App from './App.vue';
|
||||
|
||||
/* `import.meta.glob(${g}, { eager: ${isSync} })`; */
|
||||
const autoInstallModules = import.meta.glob('./plugins/!(index).ts', { eager: true });
|
||||
|
||||
import { setupPlugins } from './plugins';
|
||||
|
||||
@@ -4,10 +4,14 @@ import MetaLayouts from 'vite-plugin-vue-meta-layouts';
|
||||
export default [
|
||||
// https://github.com/dishait/vite-plugin-vue-meta-layouts
|
||||
MetaLayouts({
|
||||
target: 'src/layouts',
|
||||
excludes: ['**/!(the-)*.vue'], // 排除非 the- 开头的文件。
|
||||
metaName: 'layout',
|
||||
// defaultLayout: 'sakai-vue/AppLayout',
|
||||
// defaultLayout: 'naive-ui/AppLayout',
|
||||
defaultLayout: 'base-layout/the-base-layout',
|
||||
// !⬇️: 当设置为 `sync` 时,注意`import 'virtual:uno.css'`的顺序问题。
|
||||
// importMode: 'sync', // 默认为自动处理,SSG 时为 sync,非 SSG 时为 async
|
||||
defaultLayout: 'base-layout/base-layout',
|
||||
skipTopLevelRouteLayout: true, // 打开修复 https://github.com/JohnCampionJr/vite-plugin-vue-layouts/issues/134,默认为 false 关闭
|
||||
}),
|
||||
] satisfies PluginOption;
|
||||
|
||||
@@ -6,11 +6,12 @@ export function loadPlugin(configEnv: ConfigEnv): PluginOption {
|
||||
const env = loadEnv(configEnv.mode, process.cwd());
|
||||
|
||||
if (configEnv.command === 'build') {
|
||||
consola.info('VITE_ENABLE_VUE_DEVTOOLS is not enabled in build mode.');
|
||||
consola.info('vue-devtools plugin is not used in build mode.');
|
||||
return [];
|
||||
}
|
||||
|
||||
if (env.VITE_ENABLE_VUE_DEVTOOLS === 'true') {
|
||||
if (env.VITE_ENABLE_VUE_DEVTOOLS !== 'true') {
|
||||
consola.info('vue-devtools plugin disabled by env');
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,9 @@ export function loadPlugin(_configEnv: ConfigEnv): PluginOption {
|
||||
console.log('cloudflare plugin disabled in test mode');
|
||||
return [];
|
||||
}
|
||||
if (process.env.VITE_CLOUDFLARE_SERVER_ENABLED !== 'true') {
|
||||
console.log('cloudflare plugin disabled by env');
|
||||
return [];
|
||||
}
|
||||
return [cloudflare()];
|
||||
}
|
||||
|
||||
@@ -42,11 +42,15 @@ export const viteConfigRollupOptions: RollupOptions = {
|
||||
},
|
||||
|
||||
manualChunks: (id: string, _meta: ManualChunkMeta) => {
|
||||
/* 有一个问题: dynamic import will not move module into another chunk.
|
||||
if (['/src/layouts'].some((prefix) => id.includes(prefix))) {
|
||||
return 'layouts';
|
||||
}
|
||||
*/
|
||||
if (['/src/layouts'].some((prefix) => id.includes(prefix))) {
|
||||
return 'layouts';
|
||||
}
|
||||
|
||||
if (id.includes('meta-layouts')) {
|
||||
// console.debug(`id :>> `, id); // id :>> virtual:meta-layouts
|
||||
// 这里很奇怪,打印 id 是`virtual:meta-layouts`,但是 `'virtual:meta-layouts' === id` 却是 false
|
||||
return 'lib-meta-layouts';
|
||||
}
|
||||
|
||||
if (id.includes('index.page.vue')) {
|
||||
const parentDir = path.basename(path.dirname(id));
|
||||
|
||||
@@ -4,9 +4,11 @@ import { defineConfig, loadEnv } from 'vite';
|
||||
import { loadPlugins } from './vite-plugins/_loadPlugins';
|
||||
import { optimizeDeps } from './vite.config.optimizeDeps';
|
||||
import { viteConfigRollupOptions } from './vite.config.rollup';
|
||||
import consola from 'consola';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(async (configEnv) => {
|
||||
consola.info(`[vite.config.ts] mode: ${configEnv.mode}, command: ${configEnv.command}`);
|
||||
const { command, mode } = configEnv;
|
||||
|
||||
const isBuild = command === 'build';
|
||||
|
||||
Reference in New Issue
Block a user