新增前端vue
This commit is contained in:
42
web-vue/packages/vite/options/build.ts
Normal file
42
web-vue/packages/vite/options/build.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author ThinkGem
|
||||
*/
|
||||
import type { BuildOptions } from 'vite';
|
||||
|
||||
// 现代浏览器支持列表 https://cn.vitejs.dev/config/build-options.html#build-target
|
||||
export const viteTarget = ['chrome107', 'edge107', 'firefox104', 'safari16'];
|
||||
// 低版本浏览器支持列表,VITE_LEGACY 参数开启时有效 https://www.npmjs.com/package/@vitejs/plugin-legacy
|
||||
export const legacyTargets = ['chrome>=87', 'edge>=88', 'firefox>=78', 'safari>=14'];
|
||||
|
||||
export function createBuildOptions(viteEnv: ViteEnv): BuildOptions {
|
||||
const timestamp = new Date().getTime();
|
||||
return {
|
||||
target: viteTarget,
|
||||
cssTarget: viteTarget,
|
||||
outDir: viteEnv.VITE_OUTPUT_DIR ?? 'dist',
|
||||
// 启用 terser 缩小器,当设置 terserOptions 时才会有效
|
||||
// minify: 'terser',
|
||||
// terserOptions: {
|
||||
// compress: {
|
||||
// keep_infinity: true,
|
||||
// drop_console: viteEnv.VITE_DROP_CONSOLE,
|
||||
// },
|
||||
// },
|
||||
// 禁用报告压缩块大小,可以稍微提高构建速度
|
||||
reportCompressedSize: false,
|
||||
chunkSizeWarningLimit: 9000,
|
||||
rollupOptions: {
|
||||
maxParallelFileOps: 50,
|
||||
output: {
|
||||
entryFileNames: `assets/[name]-[hash]-${timestamp}.js`,
|
||||
experimentalMinChunkSize: 12288,
|
||||
// manualChunks: {
|
||||
// vue: ['vue', 'vue-router'],
|
||||
// antd: ['ant-design-vue', '@ant-design/icons-vue'],
|
||||
// },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
18
web-vue/packages/vite/options/css.ts
Normal file
18
web-vue/packages/vite/options/css.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author ThinkGem
|
||||
*/
|
||||
import type { CSSOptions } from 'vite';
|
||||
import { generateModifyVars } from '../theme/modifyVars';
|
||||
|
||||
export function createCSSOptions(): CSSOptions {
|
||||
return {
|
||||
preprocessorOptions: {
|
||||
less: {
|
||||
modifyVars: generateModifyVars(),
|
||||
javascriptEnabled: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
43
web-vue/packages/vite/options/define.ts
Normal file
43
web-vue/packages/vite/options/define.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author ThinkGem
|
||||
*/
|
||||
import { PackageJson, readPackageJSON } from 'pkg-types';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export async function createDefineOptions(): Promise<Record<string, any>> {
|
||||
const rootPkg: PackageJson = await readPackageJSON(process.cwd() + '/../');
|
||||
const buildPkg: PackageJson = await readPackageJSON(process.cwd() + '/../build');
|
||||
const corePkg: PackageJson = await readPackageJSON(process.cwd() + '/../packages/core');
|
||||
try {
|
||||
const __APP_INFO__ = {
|
||||
pkg: {
|
||||
dependencies: Object.fromEntries(
|
||||
Object.entries({
|
||||
...rootPkg.dependencies,
|
||||
...buildPkg.dependencies,
|
||||
...corePkg.dependencies,
|
||||
}).filter(([key]) => !key.endsWith('-lib')),
|
||||
),
|
||||
devDependencies: Object.fromEntries(
|
||||
Object.entries({
|
||||
...rootPkg.devDependencies,
|
||||
...buildPkg.devDependencies,
|
||||
...corePkg.devDependencies,
|
||||
}).filter(([key]) => !key.endsWith('-lib')),
|
||||
),
|
||||
name: rootPkg.name,
|
||||
version: rootPkg.version,
|
||||
},
|
||||
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
return {
|
||||
// __INTLIFY_PROD_DEVTOOLS__: 'false',
|
||||
__APP_INFO__: JSON.stringify(__APP_INFO__),
|
||||
};
|
||||
} catch (error) {
|
||||
console.log('createDefine', error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
12
web-vue/packages/vite/options/esBuild.ts
Normal file
12
web-vue/packages/vite/options/esBuild.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author ThinkGem
|
||||
*/
|
||||
import type { ESBuildOptions } from 'vite';
|
||||
|
||||
export function createEsBuildOptions(viteEnv: ViteEnv): ESBuildOptions {
|
||||
return {
|
||||
drop: viteEnv.VITE_DROP_CONSOLE ? ['console', 'debugger'] : [],
|
||||
};
|
||||
}
|
||||
10
web-vue/packages/vite/options/index.ts
Normal file
10
web-vue/packages/vite/options/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author ThinkGem
|
||||
*/
|
||||
export * from './build';
|
||||
export * from './css';
|
||||
export * from './define';
|
||||
export * from './esBuild';
|
||||
export * from './server';
|
||||
50
web-vue/packages/vite/options/server.ts
Normal file
50
web-vue/packages/vite/options/server.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author ThinkGem
|
||||
*/
|
||||
import type { ServerOptions, ProxyOptions } from 'vite';
|
||||
import { IncomingMessage } from 'node:http';
|
||||
|
||||
type ProxyItem = [string, string, boolean];
|
||||
type ProxyList = ProxyItem[];
|
||||
type ProxyTargetList = Record<string, ProxyOptions>;
|
||||
const httpsRE = /^https:\/\//;
|
||||
|
||||
export function createServerOptions(viteEnv: ViteEnv): ServerOptions {
|
||||
return {
|
||||
https: false as any,
|
||||
open: false,
|
||||
host: true,
|
||||
port: viteEnv.VITE_PORT,
|
||||
proxy: createProxy(viteEnv.VITE_PROXY),
|
||||
warmup: {
|
||||
clientFiles: ['./index.html', './src/{views,components}/*'],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to parse the .env.development proxy configuration
|
||||
*/
|
||||
export function createProxy(list: ProxyList = []) {
|
||||
const ret: ProxyTargetList = {};
|
||||
for (const [prefix, target, changeOrigin] of list) {
|
||||
const isHttps = httpsRE.test(target);
|
||||
// https://github.com/http-party/node-http-proxy#options
|
||||
ret[prefix] = {
|
||||
target: target,
|
||||
changeOrigin,
|
||||
ws: true,
|
||||
// https is require secure=false
|
||||
...(isHttps ? { secure: false } : {}),
|
||||
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
|
||||
bypass: (req: IncomingMessage) => {
|
||||
if (req.method === 'GET') {
|
||||
req['url'] = req['originalUrl'];
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user