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

How to specify different relative assets path #141

Closed manuel-di-iorio closed 8 years ago

manuel-di-iorio commented 8 years ago

Related to this feature request: https://github.com/jonkemp/gulp-useref/issues/106

I have this folder structure:

app
---- js
-------- script.js
---- html
-------- index.html

But instead useref compiles my assets (js) inside the html folder and I'm looking for an option to specify a different relative path for the assets.

useref html block code:

<!-- build:js /app/js/script.js -->
<script src="..\js\script1.js" async></script>
<script src="..\js\script2.js" async></script>
<!-- endbuild -->

Useref correctly replaces the path in the compiled html file of the js assets with /app/js/script.js but as written above, doesn't compile in the correct folder the assets (that is not app/html/app/js/script.js but app/js/script.js). The option needed should be like "outputRelativePath" of gulp-usemin

Thanks for attention

manuel-di-iorio commented 8 years ago

Sorry for bump, is that possible?

jonkemp commented 8 years ago

Sure. I'm looking into it.

jonkemp commented 8 years ago

Wait, would transformPath not work?

https://github.com/jonkemp/gulp-useref#optionstransformpath

manuel-di-iorio commented 8 years ago

Isn't transformPath applied on the search of the raw assets (so not the compilation) ?

"in case the path needs to be modified before **search** happens."
jonkemp commented 8 years ago

Ah yes, I see.

jonkemp commented 8 years ago

There's now a base option to specify the output folder relative to the cwd.

https://github.com/jonkemp/gulp-useref#optionsbase

nathanredblur commented 8 years ago

I have an scenario a little different.

dist/
  |-public/
    |-scripts/
  |-server
    |-view/
      |-file.jade

file.jade

<!-- build:js({client,node_modules}) scripts/client.js -->
.
.
<!-- endbuild -->

and gulp task

gulp.task('build:client', () => {
  return gulp.src('dist/server/view/file.jade', {base: 'dist'})
      .pipe(useref())
      .pipe(gulp.dest('dist'));
});

On run, gulp overwrite my file correctly 😄

<script src="scripts/client.js"></script>

But the file is create in the same path 😢 dist/scripts/client.js and I can find a way to put on the compile file in the right path dist/public/scripts/client.js

I try to set base, but I'm sure that is not the way. I need some opton that let me prefix the save path that come from "useref".

Some Ideas?

XuJinNet commented 8 years ago

+1 @nathanredblur

zce commented 8 years ago

+1 @nathanredblur

nathanredblur commented 7 years ago

I fix this, I don't remember well how but I think that was something like this.

gulp.task('build:client', () => {
  return gulp.src('dist/server/view/file.jade', {base: 'dist/public'})
      .pipe(useref())
      .pipe(gulp.dest('dist/public'));
});

If someone can test and confirm, will be nice.