add variable id in script tags using grunt

202 Views Asked by At

I have around 10 files for eg: file1.html, file2.html, fil31.html, file4.html

Each file contains a starting and end script tag with blank id='' field

I want to add id's to all the script tags in each file.

The id's are the file names.

before running grunt
eg: file1.html

<script type='text/ng-template' id=''>
     <div>Couple of other dive tags</div>
</script>

after running grunt the id filed should have an if which is the file name

eg: file1.html

<script type='text/ng-template' id='file1.html'>
     <div>Couple of other dive tags</div>
</script>

I have tried it by using couple grunt packages but can't get my head around how to make them pick file name and add them as ids.

grunt file_append
grunt-script-link-tags

Has anyone faced the same problem or knows how to solve this?

1

There are 1 best solutions below

0
patz On

Use the following code to add id's dynamically in the script tag.

Replace all the text with specified replacement using grunt replace