Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to pass the relative into the object? #9

Closed
corydorning opened this issue Jun 25, 2014 · 6 comments
Closed

Possible to pass the relative into the object? #9

corydorning opened this issue Jun 25, 2014 · 6 comments

Comments

@corydorning
Copy link

I have several HTML files i'm looping through in order to update my 'source' files with my 'dist' files. An example would be /indext.hml linking to <script src="js/main.js> and /pages/foo.html linking to the same file via <script src="../js/main.js">.

Given the relative paths, setting a static option value doesn't work. I could set a root value, but this is actually a boilerplate build system that is shared, so that makes it a tougher sell. Here's my task, didn't know if you had any ideas on how it would be possible to pass the base path in...

var gulp = require('gulp'),
    htmlreplace = require('gulp-html-replace'),
    htmlFiles = ['./**/*.html'];

gulp.task('html', function() {
    return gulp
      .src(htmlFiles , { cwd: './src', base: './src' })
      .pipe(htmlreplace({
        'css-vendor': relative.path  + 'vendor.css',
        'css-app': relative.path + 'app.css',
        'js-vendor': relative.path + 'vendor.js',
        'js-app': relative.path + 'app.js'
      }))
      .pipe(gulp.dest('./dist'));
@corydorning
Copy link
Author

I worked around this by creating a root.path object. It isn't an ideal situation, since it has to be manually updated, but will work for now. Still welcome any thoughts on accessing the relative path within htmlreplace though. (if possible)

@VFK
Copy link
Owner

VFK commented Jun 26, 2014

Hi Cory, i'm sorry i wasn't able to answer quicker. Well, as i already stated in other issues this plugin was built for text replacements. The initial idea was to allow to allow different replacements for, for example gulp dev and gulp prod and it was never intended to perform any filesystem actions. So for now unfortunately it's not possible to do what you describe sanely, but i'm glad you've found a workaround.
As a side note, i can see that these kinds of questions/suggestions became one of the most frequent things, so i guess i have no choice other than to think about how to make this plugin filesystem-aware. Thank you for convincing me :)

@corydorning
Copy link
Author

I'll keeps eyes peeled. :)

Sent from my iPhone 5

On Jun 26, 2014, at 3:51 AM, Vladimir Kucherenko notifications@github.com wrote:

Hi Cory, i'm sorry i wasn't able to answer quicker. Well, as i already stated in other issues this plugin was built for text replacements. The initial idea was to allow to allow different replacements for, for example gulp dev and gulp prod and it was never intended to perform any filesystem actions. So for now unfortunately it's not possible to do what you describe sanely, but i'm glad you've found a workaround.
As a side note, i can see that these kinds of questions/suggestions became one of the most frequent things, so i guess i have no choice other than to think about how to make this plugin filesystem-aware. Thank you for convincing me :)


Reply to this email directly or view it on GitHub.

@VFK
Copy link
Owner

VFK commented Sep 3, 2014

Ok, it took unexpectedly long time to implement this, sorry.
There is a new option resolvePaths.
I don't know if this thing can solve your problem, but after 2 months you've probably found a way to do this one way or another :) So i'm closing this issue, but of course feel free to open a new one :)

@VFK VFK closed this as completed Sep 3, 2014
@corydorning
Copy link
Author

so I'm back to this and unfortunately, I can't seem to get resolvePaths to work. here's what i have:

return gulp.src(paths.app.html.files, { base: paths.root.src)

        // optimize: replace css/js paths in index.html
        .pipe(_gulp.htmlReplace({
            'AppJS': paths.app.js.dir + paths.app.js.name
          }, {
            resolvePaths: true
          }
         ))
        .pipe(gulp.dest(paths.root.www))

This however, turns this <script src="js/app.js"></script> into this <script src="..\js\app.js"></script> which is right sans the backslash.

@VFK
Copy link
Owner

VFK commented Apr 11, 2015

@corydorning i'm sorry for the delay, i was away for some time. So, the path is correct, the slashes are wrong, right? I fixed slashes in 1.4.5, please check it out.

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

No branches or pull requests

2 participants