jaketrent / html-webpack-template

a better default template for html-webpack-plugin
MIT License
830 stars 139 forks source link

snippet work with require #82

Open ranwawa opened 5 years ago

ranwawa commented 5 years ago

common.html

<div>123123</div>

code

  plugins: [
    new HtmlWebpackPlugin({
      inject: false,
      template: HtmlWebpackTemplate,
      appMountId: 'ranwawa',
      appMountSnippet: require('./src/common.html'),  // =>  Unexpected token <
      bodyHtmlSnippet: '<div>21123</div>',

  plugins: [
    new HtmlWebpackPlugin({
      inject: false,
      template: HtmlWebpackTemplate,
      appMountId: 'ranwawa',
      appMountSnippet: require('html-loader!./src/common.html'),  // =>   Cannot find module 'html-loader!./src/common.html'
      bodyHtmlSnippet: '<div>21123</div>',
AndersDJohnson commented 4 years ago

This doesn't seem to be a problem with this library. You can't rely on Webpack loaders within your Webpack config like this. Try using fs.readFileSync.