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

HTML file in a subfolder gets different asset hash #43

Closed
nring opened this issue Oct 7, 2015 · 1 comment
Closed

HTML file in a subfolder gets different asset hash #43

nring opened this issue Oct 7, 2015 · 1 comment

Comments

@nring
Copy link

nring commented Oct 7, 2015

I'm wondering how to get gulp-rev-replace to replace file references with the same hash across multiple html files. Considering the following:

  • index.html
  • subfolder
    • index.html
  • scripts
    • main.js
  • styles
    • main.scss

And the following html statements:

index.html:

    <!-- build:css styles/main.css -->
    <link rel="stylesheet" href="/bower_components/normalize-css/normalize.css">
    <link rel="stylesheet" href="styles/main.css">
    <!-- endbuild -->

subfolder/index.html:

    <!-- build:css ../styles/main.css -->
    <link rel="stylesheet" href="/bower_components/normalize-css/normalize.css">
    <link rel="stylesheet" href="../styles/main.css">
    <!-- endbuild -->

And the following in my Gulpfile

gulp.task('html', ['styles'], () => {
  const assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});

  return gulp.src('app/**/*.html')
    .pipe(assets)
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
    .pipe($.rev())
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe($.revReplace())
    .pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
    .pipe(gulp.dest('dist'));
});

index.html will get replaced with the correct styles and scripts reference, while subfolder/index.html will get an entirely new hash.

Am I setting up my Gulpfile incorrectly?

@nring
Copy link
Author

nring commented Oct 14, 2015

Nevermind, this was more of an issue with gulp-useref than gulp-rev-replace. I ended up setting the style references in each HTML file to the root of the app directory and supplying 3 directories to search:

<!-- build:css({.tmp,app,.}) /styles/main.css -->
<link rel="stylesheet" href="/bower_components/normalize-css/normalize.css">
<link rel="stylesheet" href="/styles/main.css">
<!-- endbuild -->

Which matches the three directories supplied to gulp-useref

const assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});

@nring nring closed this as completed Oct 14, 2015
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

1 participant