Skip to content

Instantly share code, notes, and snippets.

@pi0
Last active November 11, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pi0/23b5253ac19b4ed5a70add3b971545c9 to your computer and use it in GitHub Desktop.
Save pi0/23b5253ac19b4ed5a70add3b971545c9 to your computer and use it in GitHub Desktop.
Nuxt Unattended Config Injection

Nuxt loads configuration from several places and merges. Here is the order: (first has more periority)

  • Config overrides by CLI
  • nuxt.config (format: CJS/MJS/TS can be also wrapped into an async function)
  • .nuxtrc
  • ~/.nuxtrc

In order to automatically inject some configuration without direct modification of nuxt.config, it is possible to use .nuxtrc file.

Thanks to super simpler syntax of rc9 this configuration can be injected via a shell script or package itself.

Notice 1: This feature is supported since v2.13.0

Notice 2: modules[] syntax is supported in a minor update of rc9 (1.1.0). Using progremattic usage and installing latest version is recommended.

// requires rc9 1.1.0+
echo 'modules[]="test"' >> .nuxtrc
// rc9 < 1.1.0
echo 'modules=["test"]' >> .nuxtrc
// requires rc9 1.1.0+
require('rc9').update({ 'modules[]': 'test' }, { name: '.nuxtrc' })
// rc9 < 1.1.0
require('rc9').update({ 'modules': ['test'] }, { name: '.nuxtrc' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment