Skip to content

Commit 4f2ff41

Browse files
bertybotgeoffrich
andauthored
feat: add staticDir setting (#117)
--------- Co-authored-by: Geoff Rich <[email protected]>
1 parent 1474f09 commit 4f2ff41

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ custom/
111111

112112
Also note that the adapter reserves the folder prefix `sk_render` and API route prefix `__render` for Azure functions generated by the adapter. So, if you use a custom API directory, you cannot have any other folder starting with `sk_render` or functions available at the `__render` route, since these will conflict with the adapter's Azure functions.
113113

114+
### staticDir
115+
116+
The directory where the static assets will be placed. Most of the time, you shouldn't need to set this.
117+
118+
By default, the adapter will output the static JS, CSS and HTML files to the `build/static` folder. If you want to output it to a different directory instead you can set this option.
119+
120+
```js
121+
import azure from 'svelte-adapter-azure-swa';
122+
123+
export default {
124+
kit: {
125+
...
126+
adapter: azure({
127+
staticDir: 'custom/static'
128+
})
129+
}
130+
};
131+
```
132+
114133
### customStaticWebAppConfig
115134

116135
An object containing additional Azure SWA [configuration options](https://docs.microsoft.com/en-us/azure/static-web-apps/configuration). This will be merged with the `staticwebapp.config.json` generated by the adapter.

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type Options = {
1010
customStaticWebAppConfig?: CustomStaticWebAppConfig;
1111
esbuildOptions?: Pick<esbuild.BuildOptions, 'external'>;
1212
apiDir?: string;
13+
staticDir?: string;
1314
};
1415

1516
export default function plugin(options?: Options): Adapter;

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export default function ({
4848
debug = false,
4949
customStaticWebAppConfig = {},
5050
esbuildOptions = {},
51-
apiDir: customApiDir = undefined
51+
apiDir: customApiDir = undefined,
52+
staticDir: customStaticDir = undefined
5253
} = {}) {
5354
return {
5455
name: 'adapter-azure-swa',
@@ -65,7 +66,7 @@ Please see the PR for migration instructions: https://github.com/geoffrich/svelt
6566

6667
const tmp = builder.getBuildDirectory('azure-tmp');
6768
const publish = 'build';
68-
const staticDir = join(publish, 'static');
69+
const staticDir = customStaticDir || join(publish, 'static');
6970
const apiDir = customApiDir || join(publish, 'server');
7071
const functionDir = join(apiDir, 'sk_render');
7172
const entry = `${tmp}/entry.js`;

test/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ describe('adapt', () => {
8181
expect(builder.copy).not.toBeCalledWith(expect.stringContaining('api'), 'custom/api');
8282
});
8383

84+
test('writes to custom static directory', async () => {
85+
vi.mocked(existsSync).mockImplementationOnce(() => false);
86+
const adapter = azureAdapter({ staticDir: 'custom/static' });
87+
const builder = getMockBuilder();
88+
await adapter.adapt(builder);
89+
expect(builder.writeClient).toBeCalledWith('custom/static');
90+
expect(builder.writePrerendered).toBeCalledWith('custom/static');
91+
});
92+
8493
test('logs warning when custom api directory set and required file does not exist', async () => {
8594
vi.mocked(existsSync).mockImplementationOnce(() => false);
8695
const adapter = azureAdapter({ apiDir: 'custom/api' });

0 commit comments

Comments
 (0)