-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Support for alias from jsconfig and eslint issue fix internally for alias #2000
Comments
Compared to Can you try |
For the ESLint part, should ESLint support aliases? I understand that |
@chenjiahan source: {
+ alias: {
+ api: './src/api',
+ components: './src/components',
+ hooks: './src/hooks',
+ // other alias
+ },
}, Hack: This is example how I hack for jsconfigconst root = process.cwd();
const resolve = (...args) => {
return path.resolve(root, ...args);
};
const getJSConfig = () => {
if (fs.existsSync(resolve("jsconfig.json"))) {
const jsconfig = fs.readFileSync(resolve("jsconfig.json"), "utf8");
return JSON.parse(jsconfig);
} else {
return {};
}
};
const createAlias = (customAlias = {}) => {
const { compilerOptions } = getJSConfig();
const alias = { ...customAlias };
try {
let baseUrl = root;
if (compilerOptions) {
if (
compilerOptions.baseUrl &&
fs.existsSync(resolve(root, compilerOptions.baseUrl))
) {
baseUrl = resolve(root, compilerOptions.baseUrl);
// if only base url exist then create its all folders as alias
// let src is base url so all its folders will become alias
getAliasDefaultPaths(baseUrl).forEach((folder) => {
const aliasPath = resolve(baseUrl, folder);
if (fs.existsSync(aliasPath)) {
alias[folder] = aliasPath;
}
});
}
}
return alias;
} catch (e) {
console.error(e);
}
return alias;
}; export default defineConfig({
source: {
define: publicEnv,
+ alias: createAlias()
},
// other config here
}); Is it possible for a similar solution to be integrated as a built-in feature of rsbuild? This will be helpful who is migrating from CRA to rsbuild. Following is builtin code in CRA (ejected) file: |
How about add this config to the export default {
source: {
tsconfigPath: './jsconfig.json',
},
}; |
@chenjiahan, yes it will work with |
Sure, I will add e2e case and document for this. The |
What problem does this feature solve?
jsconfig handling
We would like to have jsconfig support internally like we have with tsconfig.
Example 1:
if src has folder my-components
Example 2:
Example 3:
Eslint handling
@rsbuild/plugin-eslint
Current behaviour: right now eslint does not internally resolve alias
Expected: Eslint with
@rsbuild/plugin-eslint
should resolve alias fromrsbuild.config
tsconfig
andjsconfig
based on configuration and priority**Let me know if these things already available in build tool I will explore that.
What does the proposed API look like?
I'm in search of a solution in JavaScript projects that handles jsconfig similarly to tsconfig, enabling alias resolution. Additionally, I'm interested in default alias handling within ESLint (
@rsbuild/plugin-eslint
), ensuring it's not overwritten by external configurations, or exploring ways to prevent such overwrites specifically for aliases.The text was updated successfully, but these errors were encountered: