jturbide-gulp
v1.0.0
Published
A TypeScript-based Gulp setup class to streamline common tasks like compiling Sass, bundling/minifying JavaScript, optimizing images, processing HTML views, and copying files. The main goal is to reduce repetitive boilerplate and centralize Gulp task conf
Readme
jTurbide Gulp
A TypeScript-based Gulp setup class to streamline common tasks like compiling Sass, bundling/minifying JavaScript, optimizing images, processing HTML views, and copying files. The main goal is to reduce repetitive boilerplate and centralize Gulp task configuration.
Table of Contents
Features
- Sass Compilation: Compiles Sass (via
gulp-dart-sass), handles prefixing (autoprefixer), media query sorting, and optional minification withcssnano. - JavaScript Processing: Supports both
terseranduglifyfor minification, optional debug stripping, and file concatenation. - Image Optimization: Uses
gulp-imageminwith customizable optimizers and checks to avoid reprocessing unchanged files. - HTML/Views: Includes file includes, localization, and optional HTML minification.
- File Copy: Simple file copy tasks with optional cleaning of destination folders.
- Globally Injected Settings: Merge global or environment-specific configs automatically.
- Live Reload with BrowserSync: Automatic streaming with
browser-sync. - CLI Args: Pass
--env,--delete=false, or a custom prefix for tasks to run only a subset of them.
Installation
- Install Node.js (v14+ recommended) and Yarn or npm.
- Add this library to your project:
- Using Yarn:
yarn add jturbide-gulp - Or using npm:
npm install jturbide-gulp
- Using Yarn:
Usage
- Create a
gulpfile.ts(orgulpfile.js) in your project root. - Import the
Gulpclass and instantiate with a configuration object.
For example:
import { Gulp } from 'jturbide-gulp';- Run tasks from your terminal:
yarn gulp buildornpx gulp buildyarn gulp watchornpx gulp watchyarn gulp serveornpx gulp serve
Configuration
Below is a high-level breakdown of the most important interfaces:
SassConfigInterface: Config for Sass compilation. Key options include:src,dest,compilerOptions,minify,autoprefixer,sortMediaQueries, etc.
JsConfigInterface: Config for JavaScript processing:src,dest,terser,uglify,concat,stripDebug, etc.
ImageConfigInterface: Config for image optimization.ViewConfigInterface: Config for HTML/Views.CopyConfigInterface: Config for copying any file type.ServeConfig: Config for BrowserSync, for local development and live reloading.ConfigInterface: Main configuration object that ties them all together.StreamsInterface: Keeps track of the streams for each task type.
Global and Environment Config
You can define a top-level global config and optionally multiple env configs. When you run a command like gulp build --env=production, settings under env.production are merged into each task’s configuration.
Deleting Destinations
By default, if delete is true (in global or individual task config), the destination directory will be cleaned on each run. You can disable via CLI arg --delete=false.
Watching Specific Tasks
If you only want to watch certain tasks, pass them as CLI arguments, for example:
gulp watch --sass
This filters watch tasks to only those whose name starts with sass-. Similarly, you can do the same for build tasks.
Examples
- Basic Gulp Setup:
- Place the provided
Gulpclass andinterfacesinsrc, import them ingulpfile.ts, configure tasks, and rungulp buildorgulp watch.
- Place the provided
- Multiple Sass Configs:
- You might have multiple Sass outputs (e.g., different sets of SCSS with distinct destinations). Just add more objects to the
sassarray.
- You might have multiple Sass outputs (e.g., different sets of SCSS with distinct destinations). Just add more objects to the
- Enable/Disable Source Maps:
- Each task can enable
sourceMaps. For example,sass.sourceMaps.enable = true, and you can passinitOptionsorwriteOptions.
- Each task can enable
License
This project is licensed under the ISC License. Feel free to modify and integrate it into your workflow!
