Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuxt.config.js where build modules build only in dev mode?

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

like image 222
Alex Pilugin Avatar asked Sep 21 '25 09:09

Alex Pilugin


2 Answers

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()
...
like image 125
Batuhan Avatar answered Sep 23 '25 01:09

Batuhan


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'],
                    }
                }
            }
            : {}
    ),
})
like image 23
Justas Avatar answered Sep 23 '25 01:09

Justas