AntoineMary / grunt-angular-file-loader

Automatically sort and inject AngularJS app files depending on module definitions and usage
MIT License
5 stars 8 forks source link

Extra Empty line added with each script tag inserted #15

Closed NishantDesai1306 closed 7 years ago

NishantDesai1306 commented 7 years ago

I am using this grunt plugin and it works great but the problem I am having is that it is injecting files into index.html with an extra line (Empty)

image

So because of this issue the grunt usemin plugin is not replacing the list of script tags by the equivalent concatenated file (which gets generated properly).

When I remove the empty lines manually then usemin is able to inject the concatenated js file

NishantDesai1306 commented 7 years ago

I found the issue

at line# 161 var indentation = splitedFile[0].substr( splitedFile[0].lastIndexOf(EOL) + 1).match(/^\s*/)[0];

That '1' you're adding is for skipping EOL but in Windows machine the EOL is '\r\n' which has length of 2 so the your code only skips '\r' part (because of hardcoded 1) and hence the indentation starts with '\n' which was causing an extra empty new line before every <script ... ></script>

Solution: replace the hardcoded 1 with EOL.length so that in windows it skips 2 char i.e '\r\n'

Updated line #161: var indentation = splitedFile[0].substr( splitedFile[0].lastIndexOf(EOL) + EOL.length).match(/^\s*/)[0];