tschaub / gulp-newer

Pass through newer source files only
https://npmjs.org/package/gulp-newer
226 stars 24 forks source link

Help on setting gulp-inject with gulp-newer #32

Open raduchiriac opened 8 years ago

raduchiriac commented 8 years ago

Although I don't think it's an actual issue perse, but I can't seem to attach gulp-newer before gulp-inject. My index.html file gets rewritten every time I change my files and it's annoying.

This is what I tried:

gulp.watch('app/scripts/**/*.js', ['scripts', 'inject']);
...
gulp.task('inject', () => {
  let target = gulp.src('app/**/*.html'),
    paths = ['.tmp/scripts/**/*.js', '.tmp/styles/**/*.css'],
    sources = gulp.src(paths, { read: false });

  return target
    // .pipe(newer(paths))
    .pipe(inject(sources, { ignorePath: '.tmp/', addRootSlash: true }))
    .pipe(gulp.dest('./app/'));
});

TypeError: index.html is not a function

equinusocio commented 7 years ago

Same issue, i can't figure where put newer because before the inject pipe (passing the same src glob) it doesn't work, this is my task:

gulp.task('postcss', () => {
  const postCSSPlugins = [
    discardComments(),
    cssnext({
      browsers: ['last 2 version']
    }),
    precss(),
    cssnano({
      autoprefixer: false
    }),
    reporter({
      clearReportedMessages: true
    })
  ];
  // Parse each .css file and save the content inside parsedStyle
  var parsedStyle = gulp.src(`${paths.components}/**/*.css`, {base: "./"}).pipe(postcss( postCSSPlugins ));

  // Inject the css content inside his relative style-module.html
  gulp.src(`${paths.components}/**/style-module.html`, {base: './'})
    .pipe(inject(parsedStyle, {
      starttag: '/* inject:{{path}} */',
      endtag: '/* endinject */',
      relative: true,
      transform: (filePath, file) => {
        // return file contents as string
        return file.contents.toString('utf8')
      }
    }))
    .pipe(gulp.dest('.'));
});