How to use the env function from gulp-util
Find comprehensive JavaScript gulp-util.env code examples handpicked from public code repositorys.
gulp-util.env is a property in the Gulp utility library that provides access to the command line arguments passed to Gulp.
52 53 54 55 56 57 58 59 60 61
</pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="gulp-util"></a>4.14.1. gulp-util</h3></div></div></div><pre class="screen"> var util = require('gulp-util'); gulp.task('styles', function() { return gulp.src(['src/styles/' + (util.env.theme ? util.env.theme : 'main') + '.scss']) .pipe(compass({ config_file: './config.rb', sass : 'src/styles', css : 'dist/styles',
+ 3 other calls in file
GitHub: jacerider/aeon
18 19 20 21 22 23 24 25 26 27
let ddevStatus = false; let watchStatus = false; let drupalInfo; let url = process.env.DDEV_HOSTNAME || null; let drushCommand = 'drush'; let root = gutil.env.root; let gulpStylelint = require('gulp-stylelint'); let config = { browserSync: { proxy: 'http://localhost',
How does gulp-util.env work?
The gulp-util.env property is a part of the Gulp utility library that provides access to the command line arguments passed to Gulp when it is invoked. When you access the gulp-util.env property, it returns an object that contains all of the command line arguments passed to Gulp, along with their values. You can then use this object to check the values of different command line arguments and perform different tasks based on those values. For example, if you run the following command to invoke Gulp: bash Copy code {{{{{{{ class="!whitespace-pre hljs language-bash">gulp --env=production You can access the value of the --env command line argument in your Gulpfile.js like this: javascript Copy code {{{{{{{ const env = require('gulp-util').env; if (env.production) { // Run production tasks... } else { // Run development tasks... } In this example, we first require the gulp-util library in our Gulpfile.js. We then access the env property of the gulp-util library, which returns an object containing all of the command line arguments passed to Gulp. We then check the value of the production property of the env object, which corresponds to the value of the --env command line argument passed to Gulp. If the production property is set to true, we run production tasks, and if it is set to false (or if it is not set at all), we run development tasks. Overall, the gulp-util.env property provides a simple and flexible way to access command line arguments in a Gulpfile.js and use them to perform different tasks based on the values of those arguments.
17 18 19 20 21 22 23 24 25 26
files: [ config.dest.html + '/*.html', config.dest.css + '/*.css', config.dest.img + '/**/*' ], port: util.env.port || 3000, logLevel: 'info', // 'debug', 'info', 'silent', 'warn' logConnections: false, logFileChanges: true, open: true,
Ai Example
1 2 3 4 5 6 7 8 9 10
const gulp = require("gulp"); const env = require("gulp-util").env; gulp.task("default", function () { if (env.production) { console.log("Running production tasks..."); } else { console.log("Running development tasks..."); } });
In this example, we first require the gulp and gulp-util libraries in our Gulpfile.js. We then define a default Gulp task that logs a message to the console based on the value of the --env command line argument. If the production property of the env object is set to true, we log the message 'Running production tasks...' to the console. If it is set to false (or if it is not set at all), we log the message 'Running development tasks...' to the console. To pass command line arguments to this Gulpfile.js, you can run the following command: bash Copy code
gulp-util.log is the most popular function in gulp-util (1090 examples)