【问题标题】:Gulp-replace not working latest versionGulp-replace 不工作最新版本
【发布时间】:2018-05-08 15:26:46
【问题描述】:

// Create a scss theme file
gulp.task('theme-scss', function() {

  return gulp.src(['./retailer-theme.json']).on('error', gutil.log)
    .pipe(replace('/.*/m', 'hello')).on('error', gutil.log)
    //.pipe(jsonSass({prefix: '$theme: '})).on('error', gutil.log)
    /*.pipe(rename({
      dirname: './',
      basename: 'retailer',
      suffix: '-theme',
      extname: '.scss'
    })).on('error', gutil.log)*/
    .pipe(gulp.dest(APP_DIR + '/scss/variables/')).on('error', gutil.log)
})

尝试用 hello.enter code here 替换文件中的所有内容 Retailer-theme.json 中的文本是文本

.pipe(replace('text', 'hello')).on('error', gutil.log)

以上行按预期工作

【问题讨论】:

    标签: gulp gulp-replace


    【解决方案1】:

    实际上,如果您只是从原始正则表达式中删除引号

    .pipe(replace('/.*/m', 'hello')).on('error', gutil.log)
    

    .pipe(replace(/.*/m, 'hello')).on('error', gutil.log)
    

    我敢打赌它有效。加上引号,它只是找不到匹配项。

    【讨论】:

    • 你说的不是引号是对的,只是我必须用 g 标志替换 m 标志,使用正则表达式对象也可以,谢谢
    【解决方案2】:
    .pipe(replace(new RegExp('.*'), 'hello')).on('error', gutil.log)
    

    所以我必须创建一个正则表达式对象,如果他们在文档中有这个对象会很好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2013-04-02
      相关资源
      最近更新 更多