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

outaTiME/gulp-replace-task: Replace text patterns with applause.

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

开源软件名称(OpenSource Name):

outaTiME/gulp-replace-task

开源软件地址(OpenSource Url):

https://github.com/outaTiME/gulp-replace-task

开源编程语言(OpenSource Language):

JavaScript 87.9%

开源软件介绍(OpenSource Introduction):

gulp-replace-task

Build Status Version Prerequisite License: MIT Commitizen friendly Twitter: outa7iME

Replace text patterns with applause.

Install

From NPM:

npm install gulp-replace-task --save-dev

Usage

Assuming installation via NPM, you can use gulp-replace-task in your gulpfile like this:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/index.html')
    .pipe(
      replace({
        patterns: [
          {
            match: 'foo',
            replacement: 'bar'
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Options

Supports all the applause options.

Examples

Basic

File src/manifest.appcache:

CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/manifest.appcache')
    .pipe(
      replace({
        patterns: [
          {
            match: 'timestamp',
            replacement: Date.now()
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Multiple matching

File src/manifest.appcache:

CACHE MANIFEST
# @@timestamp

CACHE:

favicon.ico
index.html

NETWORK:
*

File src/humans.txt:

              __     _
   _    _/__  /./|,//_`
  /_//_// /_|///  //_, outaTiME v.@@version

/* TEAM */
  Web Developer / Graphic Designer: Ariel Oscar Falduto
  Site: https://www.outa.im
  Twitter: @outa7iME
  Contact: afalduto at gmail dot com
  From: Buenos Aires, Argentina

/* SITE */
  Last update: @@timestamp
  Standards: HTML5, CSS3, robotstxt.org, humanstxt.org
  Components: H5BP, Modernizr, jQuery, Bootstrap, LESS, Jade, Grunt
  Software: Sublime Text, Photoshop, LiveReload

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');
var pkg = require('./package.json');

gulp.task('default', function () {
  gulp
    .src(['src/manifest.appcache', 'src/humans.txt'])
    .pipe(
      replace({
        patterns: [
          {
            match: 'version',
            replacement: pkg.version
          },
          {
            match: 'timestamp',
            replacement: Date.now()
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Cache busting

File src/index.html:

<head>
  <link rel="stylesheet" href="/css/style.css?rel=@@timestamp">
  <script src="/js/app.js?rel=@@timestamp"></script>
</head>

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/index.html')
    .pipe(
      replace({
        patterns: [
          {
            match: 'timestamp',
            replacement: Date.now()
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Include file

File src/index.html:

<body>
  @@include
</body>

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');
var fs = require('fs');

gulp.task('default', function () {
  gulp
    .src('src/index.html')
    .pipe(
      replace({
        patterns: [
          {
            match: 'include',
            replacement: fs.readFileSync('./includes/content.html', 'utf8')
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Regular expression

File src/username.txt:

John Smith

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/username.txt')
    .pipe(
      replace({
        patterns: [
          {
            match: /(\w+)\s(\w+)/,
            replacement: '$2, $1' // Replaces "John Smith" with "Smith, John"
          }
        ]
      })
    )
    .pipe(gulp.dest('build'));
});

Lookup for foo instead of @@foo

Gulpfile:

var gulp = require('gulp');
var replace = require('gulp-replace-task');

gulp.task('default', function () {
  gulp
    .src('src/foo.txt')
    .pipe(
      replace({
        patterns: [
          {
            match: /foo/g, // Explicitly using a regexp
            replacement: 'bar'
          }
        ]
      })
    )
    .pipe(
      replace({
        patterns: [
          {
            match: 'foo',
            replacement: 'bar'
          }
        ],
        usePrefix: false // Using the option provided
      })
    )
    .pipe(
      replace({
        patterns: [
          {
            match: 'foo',
            replacement: 'bar'
          }
        ],
        prefix: '' // Removing the prefix manually
      })
    )
    .pipe(gulp.dest('build'));
});

Related

  • applause - Human-friendly replacements

License

MIT © outaTiME




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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