Using Regex in grunt-contrib-copy's "process" option not working
Asked Answered
M

1

0

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

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, " ");
                        }
                    }
                },

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

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?

Mcdavid answered 4/10, 2014 at 6:51 Comment(0)
T
2

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, " ");
                }
            }
Triboelectricity answered 19/2, 2015 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.