在grunt-contrib-copy的“进程”中使用正则表达式选项不起作用 [英] Using Regex in grunt-contrib-copy's "process" option not working

查看:276
本文介绍了在grunt-contrib-copy的“进程”中使用正则表达式选项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Grunt的复制插件从我的index.html文件中动态删除我的实时重新加载脚本。

I'm trying to remove my live reload script from my index.html file dynamically using Grunt's copy plugin.

我的Gruntfile中涉及代码的部分在这里:

The part of my Gruntfile with the code in question is here:

copy: {
            main: {
                files: [
                {
                    expand: true, 
                    src: 'index.html',
                    dest: 'build/',
                    options: {
                        process: function (content, srcpath){
                            return content.replace(/<script src = "http:\/\/localhost:9090\/livereload.js"><\/script>/g, " ");
                        }
                    }
                },

我检查了一个正则表达式测试器它显示我上面的正则表达式应该匹配我的html中的脚本。

I checked a regex tester and it showed that the regular expression I have above should match the script in my html.

尽管正则表达式测试者说它是合法的,但是我之前的匹配结果不准确,所以在这里我需要帮助来确定我的Gruntfile或我的正则表达式是否存在问题。任何建议?

Although the regex tester says it is legit, I have had inaccurate results with matches before, so I need help here in determining if there is a problem with my Gruntfile, or with my regular expression. Any suggestions?

推荐答案

您的选项位于错误位置,它们需要更高一级:

your options are in the wrong place, they need to be one level higher:

copy: {
        main: {
            files: [
            {
                expand: true, 
                src: 'index.html',
                dest: 'build/'
            },
            options: {
                process: function (content, srcpath){
                    return content.replace(/<script src = "http:\/\/localhost:9090\/livereload.js"><\/script>/g, " ");
                }
            }

这篇关于在grunt-contrib-copy的“进程”中使用正则表达式选项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆