feat: add jsconfig.json and configure path aliases#1810
Conversation
WalkthroughIntroduces path aliasing for the web project: adds jsconfig.json with baseUrl and "@/" -> "src/", and updates Vite config to resolve "@" to "./src". No other behavior changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
web/jsconfig.json (1)
1-9: Exclude build artifacts to speed up language tooling.
Add excludes to avoid VS Code/tsserver crawling large dirs.Apply this diff:
}, - "include": ["src/**/*"] + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "build"] }web/vite.config.js (1)
28-32: Optional: tighten alias match to '@/…' to avoid scoped-package collisions.
Safer pattern if you import scoped libs like '@mui/' or '@douyinfe/'.Alternative diff:
- resolve: { - alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)), - }, - }, + resolve: { + alias: [ + { find: /^@\//, replacement: fileURLToPath(new URL('./src/', import.meta.url)) }, + ], + },This ensures only paths starting with
@/are rewritten. See Rollup alias behavior. (npmjs.com)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
web/jsconfig.json(1 hunks)web/vite.config.js(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
web/vite.config.js (1)
web/src/helpers/api.js (1)
path(220-220)
🔇 Additional comments (1)
web/jsconfig.json (1)
1-9: LGTM overall — alias config matches Vite runtime.
Consistent with the Vite alias for '@'. Good addition.
| import path from 'path'; | ||
| const { vitePluginSemi } = pkg; | ||
|
|
||
| // https://vitejs.dev/config/ | ||
| export default defineConfig({ | ||
| resolve: { | ||
| alias: { | ||
| '@': path.resolve(__dirname, './src'), | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Fix ESM '__dirname' usage — it’s undefined in ESM configs.
Using __dirname here will break config loading in ESM. Prefer fileURLToPath(new URL('./src', import.meta.url)), which is Vite’s recommended pattern.
Apply this diff:
-import path from 'path';
+import { fileURLToPath } from 'node:url';
@@
- resolve: {
- alias: {
- '@': path.resolve(__dirname, './src'),
- },
- },
+ resolve: {
+ alias: {
+ '@': fileURLToPath(new URL('./src', import.meta.url)),
+ },
+ },References: Vite docs recommend this alias form; ES modules don’t define __dirname. (vitejs.dev)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import path from 'path'; | |
| const { vitePluginSemi } = pkg; | |
| // https://vitejs.dev/config/ | |
| export default defineConfig({ | |
| resolve: { | |
| alias: { | |
| '@': path.resolve(__dirname, './src'), | |
| }, | |
| }, | |
| import { fileURLToPath } from 'node:url'; | |
| const { vitePluginSemi } = pkg; | |
| // https://vitejs.dev/config/ | |
| export default defineConfig({ | |
| resolve: { | |
| alias: { | |
| '@': fileURLToPath(new URL('./src', import.meta.url)), | |
| }, | |
| }, |
🤖 Prompt for AI Agents
In web/vite.config.js around lines 23 to 32, the config uses __dirname which is
undefined in ESM; replace the alias resolution to use fileURLToPath(new
URL('./src', import.meta.url)) instead: import fileURLToPath from 'url' (or
destructure { fileURLToPath } from 'url') and construct the path via
path.resolve(fileURLToPath(new URL('./src', import.meta.url'))) (or set the
alias value directly to fileURLToPath(new URL('./src', import.meta.url)));
remove any reliance on __dirname so the config works in ESM.
feat: add jsconfig.json and configure path aliases
…bindings-i18n fix(payment,profile,admin): 修复支付二维码流程、绑定提示与后台配置说明
Summary by CodeRabbit