dc7290 / template-ejs-loader

ejs-loader with webpack5 support. Chain it to html-loader and use it with html-webpack-plugin.
MIT License
24 stars 3 forks source link

Support for latest version of html-webpack-plugin #36

Open PredragNa opened 6 months ago

PredragNa commented 6 months ago

I use template-ejs-loader on all my projects but on the latest upgrade of HTMLWebpackPlugin and HTML loader packages I can't use it since there is an error. The main problem is on the 88-th line of code where we check whether plugin.options.template === this.resource in this scenario we never pass the test because this.resource is something like: D:\[path_to_file]\index.ejs and plugin.options.template is D:\[path_to_project]\node_modules\.pnpm\html-webpack-plugin@5.6.0_webpack@5.90.3\node_modules\html-webpack-plugin\lib\loader.js!D:\[path_to_file]\index.ejs

I found out that this will solve the problem:

const currentHtmlWebpackPlugin = this._compiler?.options.plugins.filter((plugin) => typeof plugin === 'object' &&
        plugin.options &&
        plugin.options.template &&
        (plugin.options.template === this.resource || plugin.options.template.split('!')[1]))[0];

Can you consider in the near future and fix it so that it works on the latest versions of the mentioned plugins.

webdiscus commented 4 months ago

@PredragNa

you can try to use the modern html-bundler-webpack-plugin. This plugin supports EJS and many others templating engines out of the box.

The plugin replaces the functionality of the plugins and loaders:

P.S. the template-ejs-loader has not been updated for the last 2 years. It's time to switch to an actual HTML Bundler Plugin.

PredragNa commented 3 months ago

@webdiscus Thank you very much. I'll take a look.