Configuration
The module is configured under the we key of nuxt.config.ts. Every option is optional: the values below are the defaults.
ts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@weconstudio/nuxt', 'vuetify-nuxt-module'],
we: {
host: 'localhost',
bus: { enabled: true, optionsApi: true },
notify: { enabled: true, css: true, optionsApi: true },
portal: { enabled: true },
form: { enabled: true, formValidatorMixin: true },
api: {
baseUrl: '',
apiSuffix: 'api',
endpoints: [],
},
gen: true,
html: { addTags: [], addAttributes: [], forbidTags: [], forbidAttributes: [] },
},
})The resolved options are also exposed at runtime as useRuntimeConfig().public.we.
Options
| Option | Type | Default | Description |
|---|---|---|---|
host | string | 'localhost' | Host used for the "Listening" URL printed in the dev server console (together with the /gen URL). |
bus.enabled | boolean | true | Auto-imports useBus. |
bus.optionsApi | boolean | true | Provides this.$bus (see Options API). Requires bus.enabled. |
notify.enabled | boolean | true | Auto-imports useNotify and keeps notivue/nuxt enabled. |
notify.css | boolean | string[] | true | true adds notivue/notification.css and notivue/animations.css to css; an array adds those paths instead; false adds nothing. |
notify.optionsApi | boolean | true | Provides this.$notify. Requires notify.enabled. |
portal.enabled | boolean | true | Installs portal-vue (<portal> / <portal-target>), used by the form actions and titles. |
form.enabled | boolean | true | Auto-imports useForm, useFormWrapper, useValidators and useServerErrors. |
form.formValidatorMixin | boolean | true | Auto-imports the legacy formValidatorMixin. Requires form.enabled. |
api.baseUrl | string | '' | Base URL of the backend. When empty, the first entry of endpoints is used. |
api.apiSuffix | string | 'api' | Path appended to the base URL: the API URL is ${baseUrl}/${apiSuffix}, so omit leading and trailing slashes. |
api.endpoints | string[] | [] | Base URLs selectable at runtime with WeEndpointSwitcher / useApiUrl. |
gen | boolean | true | Adds the generator page at /gen. Only in development. |
html.addTags | string[] | [] | Extra tags allowed by WeHtml / useHtmlSanitizer. |
html.addAttributes | string[] | [] | Extra attributes allowed by the sanitizer. |
html.forbidTags | string[] | [] | Tags removed from the default allow-list. |
html.forbidAttributes | string[] | [] | Attributes removed from the default allow-list. |
TIP
Options are merged with the defaults, so arrays are concatenated rather than replaced. This is why html only accepts additions and exclusions instead of a full allow-list.
Always registered
Independently of the flags above, the module always registers:
- composables:
useApi,useApiFetch,useApiUrl,usePaginatedFetch,useAuth,useLux,useDateRangePresets,useDataTable,useAutoFillHeight,useImportJob,useHtmlSanitizer - every utility in
utils/(mergeDefaults,makeEnum,objectToFormData, file helpers, other helpers) - all components, with the
Weprefix (WeDatatable,WeSelect, ...) - the
$api,$fetchand$authproperties for the Options API - the module translations for
itanden(i18n) - with
vuetify-nuxt-module, thenuxtIconVuetify icon set (Icons)
App config
Datatable defaults live in app.config.ts under we.datatables. A prop set on a single WeDatatable wins over these values.
ts
// app.config.ts
import { markRaw } from 'vue'
import MyFormatter from '~/components/MyFormatter.vue'
export default defineAppConfig({
we: {
datatables: {
persist: 'local',
persistColumns: 'local',
itemsPerPage: 25,
formatters: {
my_formatter: markRaw(MyFormatter),
},
},
},
})| Key | Type | Default | Description |
|---|---|---|---|
persist | 'state' | 'local' | 'session' | 'state' | Where the table state (search, page, filters, items per page, sorting) is kept: Nuxt state, localStorage or sessionStorage. |
persistColumns | 'state' | 'local' | 'session' | 'local' | Where the selected columns are kept. |
itemsPerPage | number | — | Default items per page. |
formatters | Record<string, Component> | — | Extra cell formatters, merged over the built-in ones and matched by the field's formatter or type. |
Runtime hooks
useApi calls these Nuxt runtime hooks on every request, with the ofetch context:
| Hook | Argument |
|---|---|
we-api:onRequest | FetchContext |
we-api:onRequestError | FetchContext & { error: Error } |
we-api:onResponse | FetchContext & { response: FetchResponse } |
we-api:onResponseError | FetchContext & { response: FetchResponse } |
The hooks are not awaited, so keep handlers synchronous when they change the request.
ts
// plugins/api-locale.ts
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('we-api:onRequest', (context) => {
context.options.headers.set('Accept-Language', nuxtApp.$i18n.locale.value)
})
nuxtApp.hook('we-api:onResponseError', ({ response }) => {
console.warn('API error', response.status)
})
})Other settings
- Dates: vue-lux is configured with its own top-level
luxkey, notwe.lux. See date formatting. - Bundled modules: i18n, icon, Sanctum and notivue keep their own config keys, see Getting started.
- Vite dedupe: the module adds
vue,vuetifyand (when notify is enabled)notivuetovite.resolve.dedupe, so a single copy of each is bundled. - SBOM: building with
BUNDLE_SBOM=true(production builds only) addsrollup-plugin-sbomand writes a CycloneDX SBOM of the client bundle (cyclonedx/bom.json).