Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda