jantimon / jantimon/html-webpack-plugin

Using a html loader: raw-loader vs asset/source does not give the same output

Open
#1,707 8 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
JavaScript
Stars
10.7k
Forks
1.3k
Avg merge
1m
Merged PRs (30d)
1

Description

## Current behaviour 💣
Using `html-webpack-plugin` with a loader for html does not give the same output if I use the loader `raw-loader` or the type `asset/source`.

With the `raw-loader`, I have a classic _index.html_ corresponding to the template I provide. However, if I use the `asset/source`, I have this kind of output in my _index.html_:

> var _ = non_webpack_require("C:\Users...\node_modules\lodash\lodash.js");module.exports = function (templateParams) { with(templateParams) {return (function(data) { var __t, __p = ''; __p += 'Webpack App'; return __p })();}}

A discussion has been already opened on webpack github and the problem is with html-webpack-plugin. Find the discussion [here](https://github.com/webpack/webpack/discussions/14847).

## Expected behaviour ☀️
We should have the same output as it is mentioned in the [documentation](https://webpack.js.org/guides/asset-modules).

### Reproduction Example 👾
You can find this [repo](https://github.com/PierBJX/fluffy-enigma/tree/main/webpack/asset-modules) which reproduces the issue. Just switch between the raw-loader and the asset/source.

## Environment 🖥

Node.js v14.17.5
win32 10.0.18363
html-webpack-plugin 5.5.0
webpack version 5.64.4

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked reproduction in webpack/asset-modules and switch between raw-loader and asset/source to compare the generated index.html output. Read the webpack discussion about html-webpack-plugin to understand the reported cause. Done means asset/source produces the same expected HTML output as raw-loader and the asset-modules documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.