pugjs / babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
MIT License
810 stars 47 forks source link

Support include #112

Closed billypon closed 2 years ago

billypon commented 5 years ago

Now we can include pug file in inline template and its sub file. We can also store pug file seperately and include it.

codecov-io commented 5 years ago

Codecov Report

Merging #112 into master will decrease coverage by 1.31%. The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #112      +/-   ##
==========================================
- Coverage   87.14%   85.83%   -1.32%     
==========================================
  Files          21       21              
  Lines         459      473      +14     
  Branches      112      115       +3     
==========================================
+ Hits          400      406       +6     
- Misses         53       59       +6     
- Partials        6        8       +2
Impacted Files Coverage Δ
src/index.js 80% <42.85%> (-20%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0cb224b...95d0fc3. Read the comment docs.

billypon commented 5 years ago

The latest codecov report is wrong, the second report is right.

image

ezhlobo commented 5 years ago

@billypon thank you for your contribution. I'll take a look at it this week.

ForbesLindesay commented 5 years ago

I don't have time to review this properly, I'll leave that to @ezhlobo, but just a heads up that you could alternatively achieve this using https://github.com/pugjs/pug/tree/master/packages/pug-load and https://github.com/pugjs/pug/tree/master/packages/pug-linker which would get you much closer to feature parity with normal pug. I just wasn't sure how desirable that was given react/jsx have their own composition models.

billypon commented 5 years ago
render () {
  return pug`include ./template.pug`;
}

I found include file in this way still have problem. HMR/restart still get old result after I update template file, unless I update inline template(link rename template file).

billypon commented 5 years ago

@ForbesLindesay My implementation is not perfect. I replace include directive with source of target file simply(with indent), before parse. If you want to implement extend directive after sometime, we still need to rewrite include implementation, I think. Is it a problem or a serious problem?

ezhlobo commented 5 years ago

@billypon well, seems like doing a file read in this plugin is quite a tricky thing. Babel (plus some file handler like webpack) does a lot around the cache. So it's almost impossible to refresh the cache of other files when we change another one.

I don't feel like we can afford maintaining this approach while it's very hard for developers to use.

billypon commented 5 years ago

@ezhlobo Yes, I'm agree with you. To solve the cache problem, we need to set BABEL_DISABLE_CACHE=1 env.

I found the problem and the solution after I created PR, and I have no idea for better solution. So I think you should close this PR, or add another way to use pug in jsx.

I like using pug, prefer to use pug in jsx with separate file and some simple mixin via including other file... In some cases, pug mixin and react component can solve the same problem, sometimes I prefer to use react component, sometimes I prefer to use pug mixin. Separate file is easier maintenance and more intuitive, I think.