4

The source code: github.com/alexpilugin/ap-nuxt-firebase-ssr The issue is next: this Nuxt SSR Application uses the same nuxt.config.js file which is located in /src folder and before deployment it will be copied into the server folder.

nuxt.config.js contains a next build module which creates an issue on server (in the ssrapp firebase function)

buildModules: [
  // https://go.nuxtjs.dev/eslint
  '@nuxtjs/eslint-module'
],

My question is how to use a single nuxt.config.js file but don't use @nuxtjs/eslint on production? Log

I found that it's possible to define dev mode in nuxt.config.js file like that:
dev: process.env.NODE_ENV !== 'production' but how to use it with buildModules in order to use it with a condition?

My current solution - remove @nuxtjs/eslint-module from nuxt.config.js file

2 Answers 2

2

I think you can write a javascript function that returns related environment based modules (dev or prod).

// moduleBuilder.js

 const getModulesByEnvironment = () => {
 const env = process.env.NODE_ENV;

 if (env === 'production') {
   return [
     ...
     'brilliant_prod_module',
     ...

   ];
 } 
 else {
  return [
    ...
    'brilliant_dev_module',
    ...
   ]
 } 
 };

export { getModulesByEnvironment };

// nuxt.config.js

import { getModulesByEnvironment } from './moduleBuilder';

...
buildModules: getModulesByEnvironment()
...
2
  • Thank you. It's a very interesting approach. I definitely will try it! Commented Jan 22, 2021 at 11:25
  • My pleasure,I recommend follow simplest way to do something. It's javascript :)
    – Batuhan
    Commented Jan 22, 2021 at 12:48
2

You could use array and object destructuring together with process.env.NODE_ENV comparison like this:

nuxt.config.js:

const isProduction = process.env.NODE_ENV === 'production'

export default defineNuxtConfig({
    modules: [
        ...(isProduction ? ['nuxt-bugsnag'] : []),
        '@nuxtjs/tailwindcss',
        '@vueuse/nuxt',
    ],

    ...(
        isProduction
            ? {
                bugsnag: {
                    config: {
                        apiKey: '',
                        enabledReleaseStages: ['staging', 'production'],
                    }
                }
            }
            : {}
    ),
})

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.