klei / grunt-injector

Inject references to files into other files (think scripts and stylesheets into an html file)
MIT License
106 stars 38 forks source link

Configuration of relative paths #29

Closed felquis closed 5 years ago

felquis commented 9 years ago

Hi guys, with this config

injector: {
  options: {
    relative: true
  }
}

It should set addRootSlash to !options.relative so, addRootSlash in this case should be false but it still compiling with absolute paths. ref https://github.com/klei/grunt-injector/blob/master/tasks/injector.js#L30

So the only way to use relative paths, is to explicitly set addRootSlash to false

injector: {
  options: {
    addRootSlash: false
  }
},

npm version out put

{ npm: '2.9.0',
  http_parser: '2.3',
  modules: '14',
  node: '0.12.2',
  openssl: '1.0.1m',
  uv: '1.4.2-node1',
  v8: '3.28.73',
  zlib: '1.2.8' }
felquis commented 9 years ago

I was using ignorePath to ignore src/, I removed ignorePath and relative: true does the work and ignored src/ path, but still with a absolute path with /, if it is the right behave of relative feel free to close this issue :)

My options became:

injector: {
  options: {
    starttag: '<!-- facebook:{{ext}} -->',
    endtag: '<!-- endfacebook -->',
    relative: true,
    addRootSlash: false
  },
  browser: {
    files: {
      '<%= config.app %>/index.html': ['<%= config.app %>/bower_components/facebook-plugin/index.js'],
    }
  },
},

With this result:

<!-- facebook:js -->
  <script src="bower_components/facebook-plugin/index.js"></script>
<!-- endfacebook -->

Only using relative: true the output is:

<!-- facebook:js -->
  <script src="/bower_components/facebook-plugin/index.js"></script>
<!-- endfacebook -->

Only with relative: true should do the trick based on line 30

joakimbeng commented 9 years ago

I cannot recreate the issue. It's working for me by only setting relative: true to get paths without a leading /. Are you sure you're running the correct version of the plugin?