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

base option not working as expected #208

Open
mozmorris opened this issue May 12, 2016 · 6 comments
Open

base option not working as expected #208

mozmorris opened this issue May 12, 2016 · 6 comments

Comments

@mozmorris
Copy link

Thanks for this plugin, it's been very useful to me.

My understanding is that the base option provides a mechanism to output assets to the given directory. Perhaps it's just that I'm misunderstanding how the base option works.

I've created a test repos that hopefully demonstrates the problem: https://github.com/MozMorris/gulp-useref-example

I set the base option like so:

.pipe(useref({
    searchPath: 'static',
    base: 'dist/some/other/directory'
}))

HTML:

<!-- build:css /css/build/style.css -->
<link rel="stylesheet" href="/css/style.css">
<!-- endbuild -->

My expectation is that assets in my static folder get written to dist/some/other/directory with the final html looking like:

<link rel="stylesheet" href="/css/build/style.css">

The actual result is my assets are written to dist without the base option folder structure.

@mozmorris mozmorris changed the title base option not working as expecred base option not working as expected May 12, 2016
@marcandrews
Copy link

marcandrews commented May 30, 2016

I too cannot get the option.base to work as expected.

gulpfile.js:

gulp.task('default', function() {
  return gulp.src('src/client/*.html', { base: 'src' })
    .pipe(useref({ base: 'client' }))
    .pipe(gulpif('*.js', ngAnnotate()))
    .pipe(gulpif('*.js', uglify()))
    .pipe(gulpif('*.css', cleanCss()))
    .pipe(gulp.dest('build'));
});

*.html:

    <!-- build:css css/style.css -->
    <link rel="stylesheet" href="css/layout.css">
    <link rel="stylesheet" href="css/overlay.css">
    <!-- endbuild -->

For example, I expect style.css to be in build/client/css/, but it ends up in build/css/ with the rest of the assets instead.

@asabhaney
Copy link

My hunch is that the base is being overwritten by the gulp.dest at the end of the gulp task pipeline. A workaround for now is to control the output of the assets using gulp-if to pipe to different destinations depending of the extension of the files in the pipeline. For example:

gulp.task('default', function() {
   return gulp.src('src/client/*.html')
      .pipe(useref())
      .pipe(gulpif('**/*.html', gulp.dest('build')))
      .pipe(gulpif('**/*.js', gulp.dest('client')))
});

@0x-leen
Copy link

0x-leen commented Sep 7, 2016

+1

@mgazelle
Copy link

Unfortunately not working with me as well. Even the workaround does not work

@TM4RT
Copy link

TM4RT commented Oct 10, 2016

Same here, I am using Craft CMS and need the final concatenated script to output to my assets folder which is 3 directories up from the template files where the links to the scripts are, base does not appear to be working how I expected.

@Dizzzy
Copy link

Dizzzy commented Apr 5, 2017

Not working for me either - @asabhaney 's solution works, thanks!

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

7 participants