papiro
papiro

Reputation: 2365

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

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?

Upvotes: 0

Views: 458

Answers (1)

Andreas
Andreas

Reputation: 499

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

Upvotes: 2

Related Questions