Using Regex in the "process" option of copying grunt-contrib-copy does not work

I am trying to remove the current reload script from my index.html file dynamically using the Grunt copy plugin.

Part of my Grunt file with this code 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 the regular expression tester and showed that the regular expression I have above should match the script in my html.

Although the regexp tester says it is legal, I had incorrect results with matches before, so I need help here to determine if there is a problem with my Gruntfile or my regex. Any suggestions?

0
source share
1 answer

your options are in the wrong place, they should 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, " "); } } 
+2
source

Source: https://habr.com/ru/post/988166/


All Articles