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

Inject source file paths relative to the destination file #28

Closed stas-neverov closed 5 years ago

stas-neverov commented 9 years ago

Hi,

I wonder if it is possible to inject file paths relative to the destination file. Right now grunt-injector injects file paths relative to the gruntfile.js and there seems to be no option to control that. Except for the transform method. The problem with the transform method is that if I define it, then I'll also have to re-define how file path translates to the <script> or <link> reference. So it would be handy if there was a way to just tell grunt-injector to build paths relative to the destination file, or at least set the current working directory.

I also tried the dynamically built file objects with cwd option. The behavior has changed ('frontend/app.js' instead of './frontend/app.js') but still doesn't produce file paths relative to the cwd:

        injector: {
            js: {
                files: [{
                    expand: true,
                    cwd: 'frontend',
                    src: [
                        '**/*.js'
                    ]
                }],
                options: {
                    destFile: 'frontend/index.html'
                }
            }
        }

Please let me know if I'm missing something and I can build file references relative to the destination file. If not then I could suggest a pull request but need recommendation on how to do it:

Thanks, Stas

rickysullivan commented 9 years ago

+1

joakimbeng commented 9 years ago

It does already inject paths relative to the destination, see L126.