From 3882d5533c8d5e89568ffe03cc3a6aa7bfcf6f4e Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Thu, 30 Oct 2025 15:42:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Webpack=20=E8=B7=AF=E5=BE=84=E5=88=AB?= =?UTF-8?q?=E5=90=8D=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- craco.config.js | 21 +++++++++++++++++++-- jsconfig.json | 23 +++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/craco.config.js b/craco.config.js index 2775e3f7..fc18564c 100644 --- a/craco.config.js +++ b/craco.config.js @@ -107,11 +107,28 @@ module.exports = { ...webpackConfig.resolve, alias: { ...webpackConfig.resolve.alias, + // 根目录别名 '@': path.resolve(__dirname, 'src'), - '@components': path.resolve(__dirname, 'src/components'), - '@views': path.resolve(__dirname, 'src/views'), + + // 功能模块别名(按字母顺序) '@assets': path.resolve(__dirname, 'src/assets'), + '@components': path.resolve(__dirname, 'src/components'), + '@constants': path.resolve(__dirname, 'src/constants'), '@contexts': path.resolve(__dirname, 'src/contexts'), + '@data': path.resolve(__dirname, 'src/data'), + '@hooks': path.resolve(__dirname, 'src/hooks'), + '@layouts': path.resolve(__dirname, 'src/layouts'), + '@lib': path.resolve(__dirname, 'src/lib'), + '@mocks': path.resolve(__dirname, 'src/mocks'), + '@providers': path.resolve(__dirname, 'src/providers'), + '@routes': path.resolve(__dirname, 'src/routes'), + '@services': path.resolve(__dirname, 'src/services'), + '@store': path.resolve(__dirname, 'src/store'), + '@styles': path.resolve(__dirname, 'src/styles'), + '@theme': path.resolve(__dirname, 'src/theme'), + '@utils': path.resolve(__dirname, 'src/utils'), + '@variables': path.resolve(__dirname, 'src/variables'), + '@views': path.resolve(__dirname, 'src/views'), }, // 减少文件扩展名搜索 extensions: ['.js', '.jsx', '.json'], diff --git a/jsconfig.json b/jsconfig.json index 256380f5..7e20b6c2 100755 --- a/jsconfig.json +++ b/jsconfig.json @@ -2,7 +2,26 @@ "compilerOptions": { "baseUrl": "src", "paths": { - "*": ["src/*"] + "@/*": ["./*"], + "@assets/*": ["assets/*"], + "@components/*": ["components/*"], + "@constants/*": ["constants/*"], + "@contexts/*": ["contexts/*"], + "@data/*": ["data/*"], + "@hooks/*": ["hooks/*"], + "@layouts/*": ["layouts/*"], + "@lib/*": ["lib/*"], + "@mocks/*": ["mocks/*"], + "@providers/*": ["providers/*"], + "@routes/*": ["routes/*"], + "@services/*": ["services/*"], + "@store/*": ["store/*"], + "@styles/*": ["styles/*"], + "@theme/*": ["theme/*"], + "@utils/*": ["utils/*"], + "@variables/*": ["variables/*"], + "@views/*": ["views/*"] } - } + }, + "exclude": ["node_modules", "build", "dist"] }