Apply `.bundleignore` when copying the project to the temp directory
Is your feature request related to a problem? Please describe.
The plugin's step of copying everything to a temp directory is slow in an AWS CDK project. By default, the AWS CDK synthesizes a Cloud Assembly output directory (cdk.out) in the project directory and cdk.out contains a growing list of large files. Most notably, it retains past yarn bundle outputs as a record of deployment assets.
This directory fills up quickly because, during normal development, a CDK user may synthesize and deploy to AWS tens of times per hour. As a result, the yarn bundle step slows to a crawl as it copies more and more irrelevant data.
Describe the solution you'd like
If yarn bundle filtered files in the .bundleignore when copying the project to the temp directory, a user could choose not to copy cdk.out to the temp directory, and bundling would not slow for that reason.
Describe alternatives you've considered
I've considered periodically deleting the cdk.out directory, but then I lose the record of assets, which otherwise help diagnose deployment problems. Moreover, for my CDK construct library, I'd need to instruct my users that if using yarn.BUILD, they'll need to as well, which is not ideal.
Additional context I can't think of any.
I can see how this would just slow more and more over time.
I wonder if filtering through files as we copy will slow down the initial copy.
This s probably worth exploring to see if it helps, without breaking things. If we did it before you would have to be extra careful not to ignore anything yarn needs to resolve its dependencies.
In the mean time, can I suggest adding a clean script inline before your CDK build script like
"scripts": {
"clean": "shx rm -rf cdk.out",
"build:cdk": "...",
"build": "yarn clean && yarn build:cdk"
}
that way it's always cleaning itself. and it usually only adds a few hundred ms to the build time.