-
Notifications
You must be signed in to change notification settings - Fork 93
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
Doesn't remove injections when stream is empty #59
Comments
+1 having the same issue Found the following statement in function getNewContent (file: src/inject/inject.js):
Could this be the issue ? |
This is as intended, because the injection tags are dependent on what files to inject there's no good way to determine all tags in the target file(s) without any files to inject, and therefor it's hard to know what tags to empty. Say for instance that you have this scenario: gulp.task('styles', ['compile-styles'], function () {
return gulp.src('index.html')
.pipe(inject(gulp.src('build/**/*.css', {read: false}))
.pipe(gulp.dest('.'));
});
gulp.task('scripts', ['lint-scripts'], function () {
return gulp.src('index.html')
.pipe(inject(gulp.src('**/*.js', {read: false}))
.pipe(gulp.dest('.'));
}); If one of these streams are empty, e.g. there are no built css files then there's no way for |
hmmm, makes sense |
yes
|
Sorry for getting back to this so late... In my case I need to inject several specific files when the project is built. Since these files result in a |
@gruppjo yes, but Please provide more information, and particularly an example of what you're trying to accomplish. Because my question now is: why do you inject files if you're going to remove them anyway? (I have one injection task for development and one for production when the end result should be different) |
The following scenario: I'm building mobile apps with cordova. Cordova provides a
First block injects When running
and inject the When I run Does this help? |
I've also got a scenario where I want to inject a section of files only if a argument is passed to gulp. If that arg is missing , i want the inject block to be emptied. I'm working around it with a hack right now, but it would be nice to have an option to remove files if its an empty stream. |
Because sometimes we need to use same HTML file, where we want to inject (dev) or remove (prod) JavaScript files depending on environment.
+1, this would be very nice if we can remove/empty injected block with option like |
in case if anybody need workaround, here is how I remove scripts with gulp-replace var replace = require('gulp-replace');
...
gulp.task('remove-dev-js', function() {
return gulp.src('./html/**/*.html')
.pipe(replace(/<!-- (.*?):js -->([\S\s]*?)<!-- endinject -->/gmi, '<!-- $1:js -->\n<!-- endinject -->'))
.pipe(gulp.dest('./html'));
}); |
I submit that a build-in solution is definitely needed. Perhaps an options can be added that allows for specifying a common prefix and a removeTags flag for removing the tags marked with a prefix prior to injection. |
The desire to remove sections probably arises for many where style sheets or scripts need to be injected in a particular order for local/debug builds and as combined/minifed for release builds. For example:
For such cases, another workaround to consider is to use a single injection tag for all script types and combine multiple streams into one stream which is passed to inject. This will also allow you to conditionally combine streams based upon environment variables, etc. The best library I've found for doing this is streamqueue. Here's an example:
|
Hi,
I'm using gulp-inject to inject some files
./app/scripts/**/*.js
into my index.html. When gulp finds files, the plugin works as expected and injects all files. But when I remove all files from the filesystem the files aren't removed in the index.html. I experimented a little bit and found out that when at least one file is in the stream the plugin correctly removes all others. When I remove the last file, the index.html remains untouched resulting in 404's.I reduced the problem to this simple task to reproduce it:
Am I doing something wrong or is this the intended behavior?
The text was updated successfully, but these errors were encountered: