klei/gulp-inject

Can't insert JSX files into Jade template

viniciusbo opened this issue · 6 comments

Supposing I have the files /path/to/my/js/file.js, /path/to/my/js/file.jsx, and the following jade template:

//- inject:js
//- endinject

//- inject:jsx
//- endinject

This is the output:

//- inject:js
script(src="/path/to/my/js/file.js")
//- endinject

//- inject:jsscript(src="/path/to/my/js/file.js")//- endinject

Instead of:

//- inject:js
script(src="/path/to/my/js/file.js")
//- endinject

//- inject:jsx
script(type="text/jsx", src="/path/to/my/js/file.jsx")
//- endinject

Have anybody been throught this? Am I missing something?

Aha, I think the bug is caused by the regex being too generic in this case. Because the regex generated for //- inject:js also matches //- inject:jsx.
This doesn't happen when injecting into html because then the starttag ends in --> so there's no ambiguity there.

A quickfix until it's solved is to set the starttag option to starttag: '//- inject:{{ext}}., note the trailing . and use //- inject:js. and //- inject:jsx. in your jade template instead.

Could not get that to work with this fix, .jsx files don't get injected.
Now //- inject:jsx comment is left untouched btw.

Hey @joakimbeng I've been trying to track the source of this bug, which seems to be in src/inject/index.js:257.

Technically, adding regex word boundary \b to the end of the first group would do the right match, as seen here: http://www.regexr.com/3c501. But for some reason all inject tests fail.

If you have any thoughts that could point to the right direction would be great. I will keep hunting.

@viniciusbo sorry for the delay, but this is now solved in v4.0.0!

Nice to know @joakimbeng, thank you!