jantimon / html-webpack-plugin

Simplifies creation of HTML files to serve your webpack bundles
MIT License
10.71k stars 1.31k forks source link

ERROR in HtmlWebpackPlugin: Unable to read HTML template "babel-loader!path/to/file.js" #933

Closed mmahalwy closed 6 years ago

mmahalwy commented 6 years ago

Description

I keep getting error

ERROR in HtmlWebpackPlugin: Unable to read HTML template "babel-loader!path/to/file.js"

My config:

new HtmlWebpackPlugin({
      filename: config('serviceWorker.offlinePageFileName'),
      template: `babel-loader!${path.resolve(
        __dirname,
        './offlinePageTemplate.js'
      )}`,
      production: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeNilAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true,
      },
      inject: true,
      // We pass our config and client config script compoent as it will
      // be needed by the offline template.
      custom: {
        config,
        ClientConfig,
      },
    })

And the file:

/**
 * This is used by the HtmlWebpackPlugin to generate an html page that we will
 * use as a fallback for our service worker when the user is offline.  It will
 * embed all the required asset paths needed to bootstrap the application
 * in an offline session.
 */

// import React from 'react';
// import { renderToStaticMarkup } from 'react-dom/server';

// import HTML from '../../../shared/components/HTML';

module.exports = function generate(context) {
  // const config = context.htmlWebpackPlugin.options.custom.config;
  // const ClientConfig = context.htmlWebpackPlugin.options.custom.ClientConfig;
  // const html = renderToStaticMarkup(
  //   <HTML
  //     bodyElements={<ClientConfig nonce="OFFLINE_PAGE_NONCE_PLACEHOLDER" />}
  //   />
  // );
  const html = 'hello';
  return `<!DOCTYPE html>${html}`;
};
jantimon commented 6 years ago

Could you please try to set the template to ./offlinePageTemplate.js?

mmahalwy commented 6 years ago

Closing this. Seems that I had an older version of the plugin that made things not work

lock[bot] commented 6 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.