gulp-rev-replace 使用教程

gulp-rev-replace 使用教程

gulp-rev-replaceRewrite occurences of filenames which have been renamed by gulp-rev项目地址:https://gitcode.com/gh_mirrors/gu/gulp-rev-replace

1. 项目的目录结构及介绍

gulp-rev-replace 是一个用于替换文件路径的 Gulp 插件,主要用于在构建过程中更新文件的引用路径。以下是该项目的目录结构:

gulp-rev-replace/
├── lib/
│   ├── index.js
│   └── utils.js
├── test/
│   ├── fixtures/
│   └── index.js
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── README.md
├── package.json
└── gulpfile.js

目录结构介绍

  • lib/: 包含项目的主要代码文件。
    • index.js: 插件的主入口文件。
    • utils.js: 包含一些辅助函数。
  • test/: 包含项目的测试文件。
    • fixtures/: 包含测试用的静态文件。
    • index.js: 测试主文件。
  • .gitignore: 指定 Git 版本控制系统忽略的文件和目录。
  • .npmignore: 指定 npm 发布时忽略的文件和目录。
  • .travis.yml: Travis CI 配置文件。
  • LICENSE: 项目的许可证。
  • README.md: 项目的说明文档。
  • package.json: 项目的配置文件,包含依赖、脚本等信息。
  • gulpfile.js: Gulp 任务配置文件。

2. 项目的启动文件介绍

项目的启动文件是 lib/index.js,它是 gulp-rev-replace 插件的主入口文件。该文件导出了一个函数,用于在 Gulp 任务中使用。

// lib/index.js
var through = require('through2');
var path = require('path');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var applySourceMap = require('vinyl-sourcemaps-apply');
var replace = require('./utils').replace;

module.exports = function(options) {
  options = options || {};

  return through.obj(function(file, enc, cb) {
    if (file.isNull()) {
      this.push(file);
      return cb();
    }

    if (file.isStream()) {
      this.emit('error', new PluginError('gulp-rev-replace', 'Streaming not supported'));
      return cb();
    }

    if (file.sourceMap) {
      applySourceMap(file, file.sourceMap);
    }

    try {
      file.contents = new Buffer(replace(file.contents.toString(), options));
    } catch (err) {
      this.emit('error', new PluginError('gulp-rev-replace', err));
    }

    this.push(file);
    cb();
  });
};

3. 项目的配置文件介绍

项目的配置文件是 package.json,它包含了项目的元数据和依赖信息。以下是 package.json 的部分内容:

{
  "name": "gulp-rev-replace",
  "version": "0.4.4",
  "description": "Replace references to revisions in index files.",
  "main": "lib/index.js",
  "scripts": {
    "test": "mocha"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/jamesknelson/gulp-rev-replace.git"
  },
  "keywords": [
    "gulpplugin",
    "rev",
    "revision",
    "replace",
    "asset"
  ],
  "author": "James K Nelson <james@jamesknelson.com>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/jamesknelson/gulp-rev-replace/issues"
  },
  "homepage": "https://github.com/jamesknelson/gulp-rev-replace",
  "dependencies": {
    "gulp-util": "^3.0.7",
    "through2": "^2.0.1",
    "vinyl-sourcemaps-apply": "^0.2.1"
  },
  "devDependencies": {
    "chai": "^3.5.0",
    "gulp

gulp-rev-replaceRewrite occurences of filenames which have been renamed by gulp-rev项目地址:https://gitcode.com/gh_mirrors/gu/gulp-rev-replace

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

裴锟轩Denise

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值