📜  gulp cli - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:41:40.027000             🧑  作者: Mango

Gulp CLI - Shell-Bash

Gulp is a powerful task runner for JavaScript developers. It allows you to automate various tasks during the development process such as minifying CSS and JavaScript, live-reloading the browser, compiling SASS to CSS, and much more.

In addition to the core Gulp library, Gulp also provides a command-line interface (CLI) that you can use to interact with your Gulp project from the command-line. One convenient feature of the Gulp CLI is that it allows you to run shell commands using the "shell" task.

Running Shell Commands with Gulp

To run a shell command using Gulp, you'll first need to install the gulp-shell package. You can do this using NPM by running the following command in your terminal:

npm install gulp-shell --save-dev

After installing the gulp-shell package, you can define a new task in your Gulpfile that will execute a shell command when Gulp runs. Here's an example:

const gulp = require('gulp');
const shell = require('gulp-shell');

gulp.task('shell-example', shell.task([
  'echo "Hello, World!"'
]));

In this example, we've defined a new Gulp task called "shell-example". This task uses the gulp-shell package to run a single shell command: echo "Hello, World!".

Once you've defined your new task, you can run it using the Gulp CLI like this:

gulp shell-example

This will execute the shell command and output the result to the terminal:

[14:32:11] Using gulpfile /Users/username/projects/example/gulpfile.js
[14:32:11] Starting 'shell-example'...
Hello, World!
[14:32:12] Finished 'shell-example' after 1.15 s
Conclusion

The Gulp CLI offers a powerful way to interact with your Gulp project from the command-line. Using the gulp-shell package, you can easily execute shell commands as part of your Gulp build process.