Frugal config
Frugal expects a config object to be passed to the build
or context
methods :
import { Config } from "https://deno.land/x/frugal@0.9.5/mod.ts"
export default {
// ...
} satisfies Config;
12345
Top-level options
self
type:
string
required
This parameter should contain the absolute path of the current module using import.meta.url
:
export default {
...
self: import.meta.url;
...
}
12345
You have to give this specific value because Frugal can't infer it for you. You can use another value than import.meta.url
if you know what you are doing, but Frugal might fail to resolve some paths.
pages
type:
string[]
required
This parameter contains the relative paths to the pages module of your project :
export default {
...
pages: ["./pages/home.ts", "./pages/about.ts", "./pages/blog.ts"];
...
}
12345
outdir
type:
string
optional
default value:
"./dist/"
This parameter sets the output directory that Frugal should target. Frugal will take full ownership of this directory (potentially deleting any files in it).
export default {
...
outdir: './my-dist/';
...
}
12345
staticdir
type:
string
optional
default value:
"./static/"
This parameter should contain the relative path of the directory containing static assets that Frugal should serve. Files in this directory are copied into the /[outdir]/public
directory and served under /
.
export default {
...
static: './my-static/';
...
}
12345
importMap
type:
string
optional
This parameter should contain the path to an import map. The import map is where you would set the version of peer dependencies.
export default {
...
importMap: './import_map.json';
...
}
12345
globalCss
type:
string
optional
This parameter should contain the relative path of a stylesheet that will be bundled and made accessible to all pages via assets["style"]["global"]
.
export default {
...
importMap: './global.css';
...
}
12345
esbuild
type:
esbuild.BuildOptions
optional
With this parameter, you can pass a subset of options to esbuild. See esbuild doc for more information.
export default {
...
esbuild: {
minify: true,
splitting: true,
jsx: "automatic",
jsxImportSource: "preact",
};
...
}
12345678910
plugins
type:
Plugin[]
optional
default value:
[]
Plugins can extend Frugal capabilities via this parameter. See the Plugin section for more information.
import { cssModule } from "https://deno.land/x/frugal@0.9.5/plugins/cssModule.ts";
import { script } from "https://deno.land/x/frugal@0.9.5/plugins/script.ts";
export default {
...
plugins: [cssModule(), script()];
...
}
12345678
exporter
type:
Exporter
optional
Deploy to your favorite platform with Exporters. This parameter allows you to export your project, for example as a static site for Apache or Nginx or a bundle ready for Deno Deploy.
import { DenoExporter, UpstashCache } from "https://deno.land/x/frugal@0.9.5/mod.ts";
export default {
...
exporter: new DenoExporter(
new UpstashCache(
Deno.env.get("UPSTASH_URL"),
Deno.env.get("UPSTASH_TOKEN")
),
),
...
}
123456789101112
Server options
secure
type:
boolean
optional
default value:
false
Set this boolean to true if the server is accessible over HTTPS.
port
type:
number
optional
default value:
8000
Set the port the server listens on.
cryptoKey
type:
CryptoKey
optional
Set a key that will be used for any functionality that needs HMAC. Frugal exposes two function exportKey
and importKey
to help you create the kind of key needed :
- The function
exportKey
will generate a new key and encode it in base64. - The function
importKey
will take the base64 generated and decode the generated key.
import { importKey } from "https://deno.land/x/frugal@0.9.5/mod.ts";
export default {
...
cryptoKey: await importKey("base64-of-your-key-you-got-from-exportKey")
...
}
1234567
Do not write the base64 version of your key directly in your config. Always use secrets and environment variables to avoid leaking it.
session
type:
{ cookie?: CookieConfig, storage: SessionStorage }
optional
If you want Frugal to handle server sessions, you'll have to configure them here. The cookie
value allows you to customize the cookie used to store the session id. The storage
value defines how and where Frugal should store session data.
import { CookieSessionStorage } from "https://deno.land/x/frugal@0.9.5/mod.ts";
export default {
...
session: {
cookie: {
name: 'MY-SESSION-ID-COOKIE',
httpOnly: true,
maxAge: 60,
},
storage: new CookieSessionStorage({
name: 'MY-SESSION-STORAGE-COOKIE',
httpOnly: true,
maxAge: 60,
})
}
...
}
123456789101112131415161718
csrf
type:
{ cookieName?: string, fieldName?: string, headerName?: string, isProtected: (url: URL) => boolean }
optional
Configuration object for CSRF protection. The ìsProtected
function lets you define whether an URL should be CSRF protected. The fieldName
and headerName
will customize the name of the form field or header where Frugal should find the CSRF token. The cookieName
parameter lets you customize the cookie's name containing the CSRF token.
middlewares
type:
Middleware<Context>[]
optional
default value:
[]
Add some middleware to the server stack.