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

213
Visualizações
Is there a way to make Gulp skip or include JavaScript segments in different environments?

I'm porting some JavaScript from Jekyll to Gulp.

In Jekyll, I have a _config.yml file that includes environment variables like this:

# _config.yml
app_url: https://app.mysite.com
dev_mode: true
dev_app_url: https://devapp.local

...and in the JS source, I can use Liquid to determine if I'm in dev_mode and modify what gets outputted e.g.:

// main.js
var appUrl = '{% if site.dev_mode %}{{ site.dev_app_url }}{% else %}{{ site.app_url }}{% endif %}';

{% if site.dev_mode %}
  console.log(someVar);
  //etc
{% endif %}

Is there a way to do similar things when using Gulp, so I can have different environment vars in my JS when I'm developing and have blocks of debugging code that will be omitted when I compile for production?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you should think about using nodejs environment variables. Can be easily set on your package.json script definition if using npm. So you could end up with something similar to that :

package.json :

{
          "name": "whatever",
          "version": "1.0.0",
          "description": "",
          "main": "index.js",
          "directories": {
                    "lib": "lib"
          },
          "devDependencies": {
                    "gulp": "^4.0.2",
          },
          "scripts": {
                    "build": "export NODE_ENV=dev||set NODE_ENV=dev&& gulp build",
          },
          "repository": {
                    //...
          }
}

And within your gulp build task (because that is where the node env was define in your package.json), you can now validate the nodejs env :

    if (process.env.NODE_ENV == "dev")
    {
        //stuff()
    }
about 4 years ago · Juan Pablo Isaza Relatório
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