Skip to content
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

refactor: reintegrate publicDir, copyPublicDir logic #1932

Open
wants to merge 1 commit into
base: v2-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ export const DEFAULT_DEV_SERVER_OPTIONS: NormalizedServerConfig = {

export const DEFAULT_COMPILATION_OPTIONS: Partial<ResolvedCompilation> = {
output: {
path: './dist'
path: './dist',
copyPublicDir: true
},
sourcemap: true,
resolve: {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const outputSchema = z
publicPath: z.string().optional(),
assetsFilename: z.string().optional(),
targetEnv: z.nativeEnum(TargetEnv).optional(),
format: z.enum(['cjs', 'esm']).optional()
format: z.enum(['cjs', 'esm']).optional(),
copyPublicDir: z.boolean().optional()
})
.strict()
.optional();
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ export interface OutputConfig {
* clean output.path automatically or not
*/
clean?: boolean;
/**
* copy public directory to output.path or not
* Boolean @default true
*/
copyPublicDir?: boolean;
}

export interface ResolveConfig {
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/utils/fsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,20 @@ export async function copyPublicDirectory(
);
}
}

export function copyDir(srcDir: string, destDir: string): void {
fs.mkdirSync(destDir, { recursive: true });
for (const file of fs.readdirSync(srcDir)) {
const srcFile = path.resolve(srcDir, file);
if (srcFile === destDir) {
continue;
}
const destFile = path.resolve(destDir, file);
const stat = fs.statSync(srcFile);
if (stat.isDirectory()) {
copyDir(srcFile, destFile);
} else {
fs.copyFileSync(srcFile, destFile);
}
}
}
Loading