Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/webpack-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,25 @@ export default class CodePressWebpackPlugin {
console.warn("[CodePress] Error reading tsconfig.json:", e);
}

// Fallback: Next.js convention is @/* -> ./src/*
/**
* Fallback: Auto-detect Next.js @ alias based on directory structure.
*
* This fallback only applies when:
* 1. No @ alias was found in tsconfig.json paths
* 2. No @ alias was found in webpack resolve.alias
* 3. A "src" directory exists in the project root
*
* Next.js projects commonly use the convention:
* @/* -> ./src/*
*
* This allows imports like:
* import { Button } from "@/components/Button"
*
* For non-Next.js projects or custom project structures:
* - Explicit configuration is recommended via tsconfig.json paths
* - Example: { "compilerOptions": { "paths": { "@/*": ["./app/*"] } } }
* - This fallback will be skipped if you define your own @ alias
*/
if (!aliases.has("@")) {
const srcDir = path.join(compiler.context, "src");
if (fs.existsSync(srcDir)) {
Expand Down