chore: 📦️ 打包相关配置

This commit is contained in:
bunny 2024-05-28 10:33:08 +08:00
parent 4a12220476
commit 31230da722
5 changed files with 82 additions and 51 deletions

View File

@ -36,7 +36,7 @@ export const buildEnvironment = () => {
entryFileNames: 'js/[name]-[hash].js', // 用于指定入口文件的输出文件名格式
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 用于指定静态资源的输出文件名格式
// ? 配置文件生成方式
manualChunks: (id, meta) => {
manualChunks: id => {
// 如果是包含在包中则打包成 vendor
if (id.includes('node_modules')) {
return 'vendor';

View File

@ -1,5 +1,7 @@
import { readdir, stat } from 'node:fs';
import { formatBytes, sum } from '@pureadmin/utils';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const fileListTotal: number[] = [];
@ -30,4 +32,24 @@ const getPackageSize = options => {
});
};
export { getPackageSize };
/**
* @description
* @param dir `build`
* @param metaUrl `url``build``import.meta.url`
*/
const pathResolve = (dir = '.', metaUrl = import.meta.url) => {
// 当前文件目录的绝对路径
const currentFileDir = dirname(fileURLToPath(metaUrl));
// build 目录的绝对路径
const buildDir = resolve(currentFileDir, 'build');
// 解析的绝对路径
const resolvedPath = resolve(currentFileDir, dir);
// 检查解析的绝对路径是否在 build 目录内
if (resolvedPath.startsWith(buildDir)) {
// 在 build 目录内,返回当前文件路径
return fileURLToPath(metaUrl);
}
// 不在 build 目录内,返回解析后的绝对路径
return resolvedPath;
};
export { getPackageSize, pathResolve };

View File

@ -1,50 +1,55 @@
{
"compilerOptions": {
// any
"noImplicitAny": false,
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"baseUrl": ".",
"skipLibCheck": true,
"types": [
// "webpack-env"
"node"
],
"paths": {
"@/*": [
"src/*"
]
},
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"exclude": [
"node_modules"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
"compilerOptions": {
// any
"noImplicitAny": false,
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"baseUrl": ".",
"skipLibCheck": true,
"types": [
// "webpack-env"
"node"
],
"paths": {
"@/*": [
"src/*"
],
"@build/*": [
"build/*"
]
},
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"build/*.ts",
"vite.config.ts"
],
"exclude": [
"node_modules"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}

View File

@ -7,5 +7,7 @@
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
"include": [
"vite.config.ts"
]
}

View File

@ -4,6 +4,7 @@ import { buildEnvironment } from './build/buildEnv';
import { exclude, include } from './build/optimize';
import { getPluginsList } from './build/plugins';
import { serverOptions } from './build/server';
import { pathResolve } from './build/utils.ts';
export default defineConfig(
(): UserConfig => ({
@ -12,6 +13,7 @@ export default defineConfig(
alias: {
'@': resolve(__dirname, './src'),
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
'@build': pathResolve(),
},
},
optimizeDeps: { include, exclude },