Skip to content

Instantly share code, notes, and snippets.

@pi0

pi0/README.md

Last active Nov 11, 2020
Embed
What would you like to do?
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