question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `?` tags in `addPrefix` seems to drop all assets

See original GitHub issue

Hi,

I might have discovered a bug. I first thought it might be related to my personal setup, which has become rather big, but this small test-bed has the same results:

var gulp = require('gulp');
var inject = require('gulp-inject');

gulp.task('default', function (cb) {
    gulp.src('test/index.html')
        .pipe(inject(gulp.src(['test/*.{js,css}']), {
            addRootSlash: false,
            addPrefix: 'test'
        }))
        .pipe(gulp.dest('test/out/test-regularl'));

    gulp.src('test/index.html')
        .pipe(inject(gulp.src(['test/*.{js,css}']), {
            addRootSlash: false,
            addPrefix: '<?php echo stuff(); ?>'
        }))
        .pipe(gulp.dest('test/out/test-php'));

    cb(null);
});

Test HTML document:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <!-- inject:css --><!-- endinject -->
</head>
<body>
    <!-- inject:js --><!-- endinject -->
</body>
</html>

The first run will result in the files being injected as suspected, where the second run will not inject anything. Through trial & error, I managed to deduce that this problem occurs as soon as you insert a ? into the prefix string.

Edit; In case this might help:

OS X 10.11.1
node v4.1.2
gulp v3.9.0
gulp-inject v3.0.0

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
peiledoircommented, Jul 19, 2016

If it helps anyone else, this is what I’m currently using for adding the prefix for the Wordpress template directory for css, js & html files. Thanks for the transform workaround @humancatfood! +1

return target.pipe(inject(sources, {
            addRootSlash: false,
            transform: function (filepath) {
                var e = filepath.split('.').pop();
                    if (e === 'css') {
                        return '<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/' + filepath + '">';
                    } else if (e === 'js') {
                        return '<script src="<?php echo get_template_directory_uri(); ?>/' + filepath + '"></script>';
                    } else if (e === 'html') {
                        return '<link rel="import" href="<?php echo get_template_directory_uri(); ?>' + filepath + '">';
                    }
            }
            })).pipe(gulp.dest('.'));
3reactions
humancatfoodcommented, Jan 31, 2016

@flovan

This would be a great fix, the addPrefix option is just perfect for php inserts!

My workaround for now is the transform-option. In your case that would be


gulp.src('test/index.html')
  .pipe(inject(gulp.src(['test/*.{js,css}']), {
    addRootSlash: false,
    transform: function (filepath) {
      return '<?php echo stuff(); ?>/' + filepath;
    }
  }))
  .pipe(gulp.dest('test/out/test-php'));

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add prefix to routes in React Router v4 - Stack Overflow
Currently I am using this approach but it doesn't seem to working. When I go to http:\\localhost:3000\v1\login it shows the NotFound component.
Read more >
GNU make
To use this makefile to delete the executable file and all the object files from the directory, type: make clean. In the example...
Read more >
Work with digital assets in Optimizely PIM
Hover over a tag and click the X to remove it. Add Prefix to these assets. View the File Types Detected. This is...
Read more >
Tagging all assets in a sub directory
I'm building a project with a lot of photo assets organized into sub directories of the main photos asset source. I'm trying to...
Read more >
Task | ClearML
Delete the task as well as its output models and artifacts. Models and artifacts are deleted from their storage locations, each using its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found