Skip to content

Commit

Permalink
feat(cdk-static-site): support excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Jun 29, 2024
1 parent d1f3d51 commit 754365d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-maps-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/cdk-static-site": minor
---

Particular file patterns can now be excluded from deployment.
15 changes: 13 additions & 2 deletions packages/cdk-static-site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Examples

The minimum needed to get a StaticSite up and running is to provide the path to the directory that you want to deploy as your website.
The minimum needed to get a `StaticSite` up and running is to provide the path to the directory that you want to deploy as your website.

```ts
new StaticSite({
Expand All @@ -12,7 +12,7 @@ new StaticSite({
});
```

### With a Custom Domain Name
### With Custom Domain Name

If you provide a domain name and an optional subdomain, Route53 and Certificate Manager will be used to create the necessary resources.

Expand Down Expand Up @@ -114,3 +114,14 @@ new StaticSite(this, "StaticSite", {
invalidateCache: ["/foo/*", "/bar/baz"],
});
```

### With Custom Error Document

By default, the `StaticSite` will load a `404.html` document when the requested path does not exist. If your application uses a different document, you can override it.

```ts
new StaticSite(this, "StaticSite", {
// ...
errorDocument: "error.html",
});
```
16 changes: 9 additions & 7 deletions packages/cdk-static-site/src/constructs/StaticSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ import { Construct } from "constructs";
export interface StaticSiteProps {
source: {
directory: string;
exclude?: string[];
};
bucket?: {
accelerate?: boolean;
};
website?: {
indexDocument?: string;
errorDocument?: string;
};
errorDocument?: string;
distribution?: Omit<SiteDistributionProps, "origin">;
deployment?: {
memoryLimit?: number;
Expand Down Expand Up @@ -75,8 +73,8 @@ export class StaticSite extends Construct {
blockPublicPolicy: false,
restrictPublicBuckets: false,
}),
websiteIndexDocument: this.props.website?.indexDocument ?? "index.html",
websiteErrorDocument: this.props.website?.errorDocument ?? "404.html",
websiteIndexDocument: "index.html",
websiteErrorDocument: this.props.errorDocument ?? "404.html",
transferAcceleration: this.props.bucket?.accelerate,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
Expand Down Expand Up @@ -115,7 +113,11 @@ export class StaticSite extends Construct {

protected createDeployment() {
return new BucketDeployment(this, "BucketDeployment", {
sources: [Source.asset(this.props.source.directory)],
sources: [
Source.asset(this.props.source.directory, {
exclude: this.props.source.exclude,
}),
],
destinationBucket: this.bucket,
destinationKeyPrefix: this.props.deployment?.prefix,
memoryLimit: this.props.deployment?.memoryLimit,
Expand Down

0 comments on commit 754365d

Please sign in to comment.