Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Absolute paths required when HTML file and asset files in sibling directories #198

Closed
atwoodjw opened this issue Oct 21, 2013 · 3 comments
Closed

Comments

@atwoodjw
Copy link

I am trying to put my .html files in a "pages" directory one level down from the default app/root.

+ app
  + pages
    + page1.html
  + bower_components ...
  + scripts ...
  + styles ...

According to this, it's possible to have this structure; however, it looks like asset files must be referenced w/ absolute paths.

<!-- build:js /scripts/vendor.js -->
<!-- bower:js -->
<script src="../bower_components/jquery/jquery.js"></script>
<!-- endbower -->
<!-- endbuild -->

It would be awesome to support relative paths, like this.

<!-- build:js ../scripts/vendor.js -->
<!-- bower:js -->
<script src="../bower_components/jquery/jquery.js"></script>
<!-- endbower -->
<!-- endbuild -->

I'm trying to avoid absolute paths, since I'm building a microsite.

@maxbates
Copy link

maxbates commented Dec 2, 2013

+1 - I have scripts and templates that are loaded in different contexts and accordingly need to reference relative paths

@sindresorhus
Copy link
Member

PR welcome.

@danemacaulay
Copy link

you can work around this by using the patterns option but its a little ugly, heres a sample config

        // Performs rewrites based on filerev and the useminPrepare configuration
        usemin: {
            html: 'dist/html/index.html',
            options: {
                assetsDirs: ['dist'],    // defaults to dir of html ie dist/html
                patterns: {
                    html: [
                        [
                            /<script.+src=['"]([^"']+)["']/gm,
                            'Update the Javascript assets to reference the correct path',
                            undefined,
                            function (path) {
                                return '../'.concat(path);
                            }
                        ],
                        [
                            /<link[^\>]+href=['"]([^"']+)["']/gm,
                            'Update the CSS assets to reference the correct path.',
                            undefined,
                            function (path) {
                                return '../'.concat(path);
                            }
                        ],
                    ]
                }
            }
        },

Only downside is that, well, you have this in your GruntFile now, and you lose all the handy default replacement patterns included in lib/fileprocessor.js

would it make sense to merge defaults into this setting here?

hmm, would be nice to make this smarter, looking into the revvedfinder, fix is in there methinks

  // should return paths relative to index.html
  var filepaths = this.getRevvedCandidates(file, searchPaths);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants