pugjs / pug-loader

Pug loader module for Webpack
MIT License
425 stars 119 forks source link

Pug locals compilation #88

Open var-bp opened 7 years ago

var-bp commented 7 years ago

Hello, I have a problem. I need to compile and include another file passed by function.

// index.jade
// I'm using bemto
mixin foo()
  - var blockName = 'some-block' // simplified example
  +b.some-block
    != htmlWebpackPlugin.options.getBlock(blockName)
+foo()

// some-block.pug
+e.element Some text

// webpack.config.js
use: {
 loader: 'pug-loader',
}
new HtmlWebpackPlugin({
  filename: index.html,
  template: index.pug
  getBlock: function(blockName) {
    return fs.readFileSync(`${blockName}.pug`, { encoding: 'utf8' });
  },
})

What I get:

// index.html
<div class="some-block">+e.element Some text</div>

What I need :

// index.html
<div class="some-block">
  <div class="some-block__element">Some text</div>
</div>

Is this possible? I would be grateful if you help.

laurenskling commented 6 years ago

seems like fs.readFileSync is just giving you the file contents, which is not parsed by the pug-loader (via webpack). Because it's not required?