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.

Possible to dynamically inject files depends on the name of file to be injected ?

See original GitHub issue

I have a huge HTML file, with many files to inject, but it seems not DRY to do this:

var myTransform =  function (filepath, file) {
  return file.contents.toString('utf8');
  .pipe(inject(gulp.src('file1.html'),  { starttag: '<!-- inject:file1:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file2.html'),  { starttag: '<!-- inject:file2:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file3.html'),  { starttag: '<!-- inject:file3:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file4.html'),  { starttag: '<!-- inject:file4:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file5.html'),  { starttag: '<!-- inject:file5:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file6.html'),  { starttag: '<!-- inject:file6:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file7.html'),  { starttag: '<!-- inject:file7:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file8.html'),  { starttag: '<!-- inject:file8:html} -->'), transform: myTransform))
  .pipe(inject(gulp.src('file9.html'),  { starttag: '<!-- inject:file9:html} -->'), transform: myTransform))

Any way to eliminate the duplication? Thanks!

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:2
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

JustMaiercommented, Jul 25, 2015

+1 here as well. Would be great if we could do something like:

.pipe(inject(gulp.src(['injects/*.html']), {
    starttag: '<!-- inject:{{filename}}:{{ext}} -->',
    transform: function (filePath, file) {
        return file.contents.toString('utf8')
zhecommented, Oct 31, 2015

Same here. I really prefer @JustMaier 's way which includes a {{filename}} option:

.pipe(inject(gulp.src(['injects/*.html']), {
    starttag: '<!-- inject:{{filename}}:{{ext}} -->',
    transform: function (filePath, file) {
        return file.contents.toString('utf8')
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Is it possible to dynamically manage @Named injection ...
This is a possible solution for you using IterableProvider (which has a "named" method on it to choose a specific named version at...
Read more >
Dynamic-link Library Injection, Sub-technique T1055.001 ...
ID Name Description S0024 Dyre Dyre injects into other processes to load modules. S0081 Elise Elise injects DLL files into iexplore.exe. S0613 PS1 PS1 can inject...
Read more >
Require file dynamically by variable · Issue #6391 - GitHub
I want to require files like: var component = require("myApp/components/" + name); Seems like require wants passed string to be static, not dependent...
Read more >
Loading Script Files Dynamically - KIRUPA
Mainly, we have a script element that contains some code to dynamically load a file called easing.js and append it to the bottom...
Read more >
Dependency injection in Android | Android Developers
These required classes are called dependencies, and in this example the Car class is dependent ... so constructor injection is not possible.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found