Skip to content

Commit 98fae2b

Browse files
committed
feat: 🎸 add @/* alias for ./src/*
1 parent 16e9ec4 commit 98fae2b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Diff for: packages/cli/src/plugins/aliasPlugin.mjs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createLogger } from '../logger.mjs';
2+
3+
import chalk from 'chalk';
4+
5+
export function aliasPlugin({ definition, cliConfig }) {
6+
const { projectFolder } = cliConfig;
7+
const logger = createLogger('aliasPlugin', cliConfig);
8+
return {
9+
name: 'aliasPlugin',
10+
setup(build) {
11+
logger.debug(`Setup plugin for "${chalk.cyan(definition.name)}" task.`);
12+
13+
build.onResolve({ filter: /^@\// }, async (args) => {
14+
const result = await build.resolve(args.path.replace(/^@\//, `./`), {
15+
kind: 'import-statement',
16+
resolveDir: `${projectFolder}/src/`,
17+
});
18+
19+
if (result.errors.length > 0) {
20+
return { errors: result.errors };
21+
}
22+
return { path: result.path };
23+
});
24+
},
25+
};
26+
}

Diff for: packages/create-widget/template/jsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./",
4+
"paths": {
5+
"@/*": [
6+
"./src/*"
7+
],
8+
}
9+
}
10+
}

Diff for: packages/create-widget/template/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
},
3838
"engines": {
3939
"node": ">=20.0.0"
40+
},
41+
"imports": {
42+
"@/*": "./src/*"
4043
}
4144
}

0 commit comments

Comments
 (0)