How can I set an environment variable as gulp task?

后端 未结 5 1047
感动是毒
感动是毒 2020-12-23 18:45

I don\'t want type the extra arguments NODE_ENV=\'production\' gulp every time I run gulp to set an environment variable.

I would rather set the environ

5条回答
  •  难免孤独
    2020-12-23 19:27

    You can also define it as a script in your package.json

    {
      "name": "myapp",
      "scripts": {
        "gulp": "NODE_ENV='development' gulp",
        "gulp-build": "NODE_ENV='production' gulp"
      },
      ...
    }
    

    And run it with npm run gulp-build. This has a few benefits

    • You can define arguments easily instead of typing them every time
    • Global gulp installation isn't required (same for other tools, like webpack)
    • You can define multiple variants with different environment variables and(or) arguments without changing the gulpfile (as you can see above - gulp and gulp-build for development and production respectively)

提交回复
热议问题