jonkemp / gulp-useref

Parse build blocks in HTML files to replace references to non-optimized scripts or stylesheets.
MIT License
705 stars 93 forks source link

Add support for absolute paths with the new option "base" #152

Open manuel-di-iorio opened 8 years ago

manuel-di-iorio commented 8 years ago

First of all, thank you to have inserted the new option ( https://github.com/jonkemp/gulp-useref/issues/141#issuecomment-154697616 ).

The issue is simple, this new option only supports paths relative to the script location. Useref should be able to understand when the base path is absolute or not, using the native path.isAbsolute(). That's it :)

PS: The absolute path support is already implemented for the searchPath option.

jonkemp commented 8 years ago

I'm afraid I don't understand the problem this should solve.

manuel-di-iorio commented 8 years ago
useref({
    base: "../relative" //supports relative paths
    base: "I:\\Users\\Computer\\Desktop" //<-- not supported
}) 

The base option is the location of the assets (js, css) and it's relative to process.cwd() Unfortunally cwd is not always the root folder of the app, ie. running the gulpfile inside another folder, so that I have to write something like: "../../myAppName/public/www". A unexpected behavior if I have to share the config of the gulpfile

You may add the support for absolute paths for that option:

var path = require("path");

if (!path.isAbsolute(options.base)) 
    options.base = path.join(process.cwd(), options.base);