首页 > 解决方案 > Gulp-replace 不工作最新版本

问题描述

// 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)

上面的行按预期工作

标签: gulpgulp-replace

解决方案


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

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

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

我敢打赌它有效。有了引号,它就找不到匹配项了。


推荐阅读