帕格当地人用webpack编译

时间:2017-04-27 20:03:12

标签: pug webpack-2 html-webpack-plugin

我有Pug和Webpack 2的问题。我需要编译并包含由函数传递的另一个文件。

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

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

// webpack.config.js
use: [
  'html-loader', // without it shows an error
  {
    loader: "pug-html-loader",
    options: {
      data: {
        getBlock: function(blockName) {
          return fs.readFileSync(`${blockName}.pug`, { encoding: 'utf8' });
        },
      }
    }
  }
]
new HtmlWebpackPlugin({
  filename: index.html,
  template: index.pug,
  // same bad result
  // getBlock: function(blockName) {
  // return fs.readFileSync(`${blockName}.pug`, { encoding: 'utf8' });
  // },
})

我得到了什么:

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

我需要什么:

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

这可能吗?如果你帮忙,我将不胜感激。

0 个答案:

没有答案