Grunt replace string in multiple files with a little difference

I need to do similar replacements in multiple files using Grunt. I am trying to use tasks string-replace, but unfortunately for each case I need to define a new task:

'string-replace': {
        de: {
            files: { 'public/de.html': 'src/templates/index.html' },
            options: { replacements: [
                { pattern: /<!-- @locale-vendor-replacement -->/ig, replacement: '<script src="js/i18n/angular-locale_de-ch.js"></script>'},
                { pattern: /<!-- @locale-name-replacement -->/ig, replacement: 'de'}
            ]}
        },
        fr: {
            files: { 'public/fr.html': 'src/templates/index.html' },
            options: { replacements: [
                { pattern: /<!-- @locale-vendor-replacement -->/ig, replacement: '<script src="js/i18n/angular-locale_fr-ch.js"></script>'},
                { pattern: /<!-- @locale-name-replacement -->/ig, replacement: 'fr'}
            ]}
        },

        ...

I want to define a list of files or even a template, for example. public/(*).htmland then specify the replacement

"@placeholder" -> "<script src="js/i18n/angular-locale_$1.js"></script>" 

or something like that. Any suggestions?

+4
source share

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


All Articles