diff --git a/API.md b/API.md
index e0eac4e..cb7e2c3 100644
--- a/API.md
+++ b/API.md
@@ -839,6 +839,7 @@ const nodejsBuildProps: NodejsBuildProps = { ... }
| buildEnvironment
| {[ key: string ]: string}
| Environment variables injected to the build environment. |
| destinationKeyPrefix
| string
| Key prefix to deploy your build artifact. |
| distribution
| aws-cdk-lib.aws_cloudfront.IDistribution
| The distribution you are using to publish you build artifact. |
+| excludeCommonFiles
| boolean
| If true, common unnecessary files/directories such as .DS_Store, .git, node_modules, etc are excluded from the assets by default. |
| nodejsVersion
| number
| The version of Node.js to use in a build environment. Available versions: 12, 14, 16, 18, 20. |
| outputEnvFile
| boolean
| If true, a .env file is uploaded to an S3 bucket with values of `buildEnvironment` property. You can copy it to your local machine by running the command in the stack output. |
| workingDirectory
| string
| Relative path from the build directory to the directory where build commands run. |
@@ -939,6 +940,19 @@ If any specified, the caches are invalidated on new artifact deployments.
---
+##### `excludeCommonFiles`Optional
+
+```typescript
+public readonly excludeCommonFiles: boolean;
+```
+
+- *Type:* boolean
+- *Default:* true
+
+If true, common unnecessary files/directories such as .DS_Store, .git, node_modules, etc are excluded from the assets by default.
+
+---
+
##### `nodejsVersion`Optional
```typescript
diff --git a/src/nodejs-build.ts b/src/nodejs-build.ts
index a3b889c..18c0a46 100644
--- a/src/nodejs-build.ts
+++ b/src/nodejs-build.ts
@@ -75,6 +75,12 @@ export interface NodejsBuildProps {
* @default false
*/
readonly outputEnvFile?: boolean;
+ /**
+ * If true, common unnecessary files/directories such as .DS_Store, .git, node_modules, etc are excluded
+ * from the assets by default.
+ * @default true
+ */
+ readonly excludeCommonFiles?: boolean;
}
/**
@@ -229,9 +235,11 @@ curl -v -i -X PUT -H 'Content-Type:' -d "@payload.json" "$responseURL"
this.grantPrincipal = project.grantPrincipal;
+ const commonExclude = ['.DS_Store', '.git', 'node_modules'];
const assets = props.assets.map((assetProps) => {
const asset = new Asset(this, `Source-${assetProps.path.replace('/', '')}`, {
...assetProps,
+ ...(props.excludeCommonFiles ?? true ? { exclude: [...commonExclude, ...(assetProps.exclude ?? [])] } : {}),
});
asset.grantRead(project);
return asset;
diff --git a/test/integ.nodejs-build.ts b/test/integ.nodejs-build.ts
index 172a8de..84cee8e 100644
--- a/test/integ.nodejs-build.ts
+++ b/test/integ.nodejs-build.ts
@@ -20,7 +20,7 @@ class TestStack extends Stack {
assets: [
{
path: '../example/example-app',
- exclude: ['dist', 'node_modules'],
+ exclude: ['dist'],
},
],
destinationBucket: dstBucket,