Won Oh
Won Oh

Reputation: 336

grunt-injector not injecting the file

I am using grunt-injector to inject client-side dependencies.

Here's how my "injector" part of my initConfig looks like:

    "injector": {
      "options": {
        "template": "public/dist/index.html",
        "destFile": "public/dist/index.gen.html"
      },
      "local_dependencies": {
        "files": {
          "public/dist/index.html": [
            "public/**/*.js",
            "public/**/*.css"
          ]
        }
      }
    }

and my public/dist/index.html reads

<!DOCTYPE html>
<html>
  <head>
    <!-- injector:css-->
    <!-- endinjector-->
  </head>
  <body ng-cloak ng-app="primary">
    <!-- injector:js-->
    <!-- endinjector-->
  </body>
</html>

and I did

grunt.loadNpmTasks("grunt-injector");

and register "injector" as part of my task.

However, executing grunt will just generate, but not inject. to "index.gen.html" file.

What should I do? any suggestions?

Upvotes: 1

Views: 786

Answers (1)

Won Oh
Won Oh

Reputation: 336

The problem was caused by the trailing space. Since I was using Pug (formerly Jade) to compile my HTML, it was generating <!-- injector:css--> instead of <!-- injector:css --> (since the Pug-equivalent is // injector:css) and the trailing space was autoremoved by my editor.

Adding

"options": {
    "starttag": "<!-- injector:{{ext}}-->",
    "endtag": "<!-- endinjector-->"
},

fixed the problem

Upvotes: 2

Related Questions