klei/gulp-inject

Strips tag declaration after processing

mitchrenton opened this issue · 2 comments

Hi.

We have different base URLs for our environments and therefore prepend the assets with the dynamic URL, problem is, the PHP gets stripped, is there a way to prevent this?

So our inject goes from this

<!-- inject:js -->
<script src="<?php echo $config['base_url']; ?>/assets/javascript/boolean/app.boolean.js"></script>
<!-- endinject -->

to this...

<!-- inject:js -->
<script src="/assets/javascript/boolean/app-0308673a34.boolean.min.js"></script>
<!-- endinject -->

You can use the addPrefix option

gulp.src('index.php')
  .pipe(inject(gulp.src('path/*.js', {read: false}), {
    addPrefix: '<?php echo $config['base_url']; ?>'
  }))
  .pipe(gulp.dest('dest/'));

Hi Joakim,

Thanks for getting back to me. I'm almost there!

The problem is I can't escape the ? in the JavaScript string...

addPrefix: '<\\?php echo $config[\'base_url\']; \\?>',

I'm no JavaScript expert but everywhere I've read seems to suggest that double forward slashes \\ should escape a question mark.

Any ideas?