chore: 📦️ 打包相关配置
This commit is contained in:
parent
4a12220476
commit
31230da722
|
@ -36,7 +36,7 @@ export const buildEnvironment = () => {
|
||||||
entryFileNames: 'js/[name]-[hash].js', // 用于指定入口文件的输出文件名格式
|
entryFileNames: 'js/[name]-[hash].js', // 用于指定入口文件的输出文件名格式
|
||||||
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 用于指定静态资源的输出文件名格式
|
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]', // 用于指定静态资源的输出文件名格式
|
||||||
// ? 配置文件生成方式
|
// ? 配置文件生成方式
|
||||||
manualChunks: (id, meta) => {
|
manualChunks: id => {
|
||||||
// 如果是包含在包中则打包成 vendor
|
// 如果是包含在包中则打包成 vendor
|
||||||
if (id.includes('node_modules')) {
|
if (id.includes('node_modules')) {
|
||||||
return 'vendor';
|
return 'vendor';
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { readdir, stat } from 'node:fs';
|
import { readdir, stat } from 'node:fs';
|
||||||
import { formatBytes, sum } from '@pureadmin/utils';
|
import { formatBytes, sum } from '@pureadmin/utils';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { dirname, resolve } from 'node:path';
|
||||||
|
|
||||||
const fileListTotal: number[] = [];
|
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 };
|
||||||
|
|
101
tsconfig.json
101
tsconfig.json
|
@ -1,50 +1,55 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
// 是否在表达式和声明上有隐含的any类型时报错
|
// 是否在表达式和声明上有隐含的any类型时报错
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2020",
|
"ES2020",
|
||||||
"DOM",
|
"DOM",
|
||||||
"DOM.Iterable"
|
"DOM.Iterable"
|
||||||
],
|
],
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"types": [
|
"types": [
|
||||||
// "webpack-env"
|
// "webpack-env"
|
||||||
"node"
|
"node"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": [
|
"@/*": [
|
||||||
"src/*"
|
"src/*"
|
||||||
]
|
],
|
||||||
},
|
"@build/*": [
|
||||||
/* Bundler mode */
|
"build/*"
|
||||||
"moduleResolution": "bundler",
|
]
|
||||||
"allowImportingTsExtensions": true,
|
},
|
||||||
"resolveJsonModule": true,
|
/* Bundler mode */
|
||||||
"isolatedModules": true,
|
"moduleResolution": "bundler",
|
||||||
"noEmit": true,
|
"allowImportingTsExtensions": true,
|
||||||
"jsx": "preserve",
|
"resolveJsonModule": true,
|
||||||
/* Linting */
|
"isolatedModules": true,
|
||||||
"strict": true,
|
"noEmit": true,
|
||||||
"noUnusedLocals": true,
|
"jsx": "preserve",
|
||||||
"noUnusedParameters": true,
|
/* Linting */
|
||||||
"noFallthroughCasesInSwitch": true
|
"strict": true,
|
||||||
},
|
"noUnusedLocals": true,
|
||||||
"include": [
|
"noUnusedParameters": true,
|
||||||
"src/**/*.ts",
|
"noFallthroughCasesInSwitch": true
|
||||||
"src/**/*.tsx",
|
},
|
||||||
"src/**/*.vue"
|
"include": [
|
||||||
],
|
"src/**/*.ts",
|
||||||
"exclude": [
|
"src/**/*.tsx",
|
||||||
"node_modules"
|
"src/**/*.vue",
|
||||||
],
|
"build/*.ts",
|
||||||
"references": [
|
"vite.config.ts"
|
||||||
{
|
],
|
||||||
"path": "./tsconfig.node.json"
|
"exclude": [
|
||||||
}
|
"node_modules"
|
||||||
]
|
],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.node.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
|
@ -7,5 +7,7 @@
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"strict": true
|
"strict": true
|
||||||
},
|
},
|
||||||
"include": ["vite.config.ts"]
|
"include": [
|
||||||
|
"vite.config.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { buildEnvironment } from './build/buildEnv';
|
||||||
import { exclude, include } from './build/optimize';
|
import { exclude, include } from './build/optimize';
|
||||||
import { getPluginsList } from './build/plugins';
|
import { getPluginsList } from './build/plugins';
|
||||||
import { serverOptions } from './build/server';
|
import { serverOptions } from './build/server';
|
||||||
|
import { pathResolve } from './build/utils.ts';
|
||||||
|
|
||||||
export default defineConfig(
|
export default defineConfig(
|
||||||
(): UserConfig => ({
|
(): UserConfig => ({
|
||||||
|
@ -12,6 +13,7 @@ export default defineConfig(
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, './src'),
|
'@': resolve(__dirname, './src'),
|
||||||
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
||||||
|
'@build': pathResolve(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
optimizeDeps: { include, exclude },
|
optimizeDeps: { include, exclude },
|
||||||
|
|
Loading…
Reference in New Issue