• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

gunpowderlabs/gulp-environments: A library for conditionally executing code in G ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

gunpowderlabs/gulp-environments

开源软件地址(OpenSource Url):

https://github.com/gunpowderlabs/gulp-environments

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-environments

A Gulp plug-in that makes it convenient to create separate environments, such as development and production, to run your tasks in.

CircleCI

Basic usage

Install the plugin using npm:

$ npm install --save-dev gulp-environments

Require the plug-in somewhere in your gulpfile.js

var environments = require('gulp-environments');

By default, the library defines two environments: development and production. For convenience sake, it is recommended to assign them to local variables:

var development = environments.development;
var production = environments.production;

You can use these environments as predicates (functions returning true/false depending on whether the given environment is active):

var source = production() ? "source.min.js" : "source.js";

You can also use the environment as a filter in you Gulp pipelines:

gulp.src(paths.js)
  // this will only init sourcemaps in development
  .pipe(development(sourcemaps.init()))
  .pipe(concat("app.js"))
  // only write out sourcemaps in development
  .pipe(development(sourcemaps.write('.')))
  // only minify the compiled JS in production mode
  .pipe(production(uglify()))
  .pipe(gulp.dest("./public/app/js/"));

Setting the environment

By default, gulp-environments uses the NODE_ENV environment variable to determine environment:

NODE_ENV=development gulp build

You can also pass a command line flag --env to set it (takes precedence over NODE_ENV):

gulp build --env development

Alternatively, you can define a task that would set the appropriate environment before executing other tasks:

gulp.task('set-dev', development.task);

and run it (or make it a dependency of a task that should also be run in that environment):

gulp set-dev build

Finally, you can always set the environment by hand in your task definition:

environments.current(development);

Other environments

You don't have to limit yourself to using only the two provided environments. You can create other ones by calling (in the example, we are creating an environment called staging):

var staging = environments.make("staging");

License

MIT

Author

Adam Pohorecki




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
KnowTheCode/UpGulp: A Gulp Starter for your WordPress project发布时间:2022-06-21
下一篇:
RobbinHabermehl/gulp-angular-translate发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap