Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
Want to use either of the 2 different .js files depending upon webpack build mode

This is my first question here.

I have two scripts: script.js and script-dev.js

Both scripts are located in 'static' folder(I am using NUXTJS)

Now, when webpack production build is used, ONLY script.js should be used and script-dev.js should be excluded/not used (sorry if i am using any incorrect term)

Similarly, for webpack development build, ONLY script-dev.js should be used and script.js should be excluded/not used.

(I am doing so because I will be using two diff API Urls in both files and script-dev.js will be used only for testing code in development. )

I have a nuxt.config.js file in root folder.

Can anyone please help me how can I modify the nuxt.config.js (or any other way you know) to achieve the above result.

here is my current nuxt.config.js and I have extended the webpack config as shown below (sorry for the improper formatting):

export default {
  telemetry: false,
  mode: 'universal',
  server: {
    host: '0.0.0.0',
    port: 3000,
  },
  env: {
    API_URL: process.env.API_URL,
  },
  serverMiddleware: [
    {
      path: '/r',
      handler: '~/api/redirector.js',
    },
  ],
  build: {
    extend(config, ctx) {
      if (ctx.isDev) {
        config.module.rules.push({
          test: /.js$/,
          exclude: [path.resolve(__dirname, 'static/script.js')],
        })
      } else {
        config.module.rules.push({
          test: /.js$/,
          exclude: [path.resolve(__dirname, 'static/script-dev.js')],
        })
      }
    },
  },
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda