Skip to content

Commit b09b439

Browse files
committed
fix: add support for publicPath: 'auto' in combination with type: 'asset/resource'
1 parent a97234e commit b09b439

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

examples/javascript/dist/webpack-5/bundle.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
/*
2-
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
3-
* This devtool is not neither made for production nor for readable output files.
4-
* It uses "eval()" calls to create a separate source file in the browser devtools.
5-
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
6-
* or disable the default devtool with "devtool: false".
7-
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
8-
*/
91
/******/ (() => { // webpackBootstrap
102
/******/ var __webpack_modules__ = ({
113

124
/***/ 184:
135
/***/ ((module) => {
146

157
"use strict";
16-
eval("// This file is used for frontend and backend\n\n\n// If compiled by the html-webpack-plugin\n// HTML_WEBPACK_PLUGIN is set to true:\nvar backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined';\n\nmodule.exports = function () {\n return 'Hello World from ' + (backend ? 'backend' : 'frontend');\n};\n\n\n//# sourceURL=webpack:///./universial.js?");
8+
// This file is used for frontend and backend
9+
10+
11+
// If compiled by the html-webpack-plugin
12+
// HTML_WEBPACK_PLUGIN is set to true:
13+
var backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined';
14+
15+
module.exports = function () {
16+
return 'Hello World from ' + (backend ? 'backend' : 'frontend');
17+
};
18+
1719

1820
/***/ }),
1921

2022
/***/ 636:
2123
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2224

2325
"use strict";
24-
eval("__webpack_require__.r(__webpack_exports__);\n// extracted by mini-css-extract-plugin\n\n\n//# sourceURL=webpack:///./main.css?");
26+
__webpack_require__.r(__webpack_exports__);
27+
// extracted by mini-css-extract-plugin
28+
2529

2630
/***/ })
2731

@@ -64,7 +68,14 @@ eval("__webpack_require__.r(__webpack_exports__);\n// extracted by mini-css-extr
6468
/******/
6569
/************************************************************************/
6670
(() => {
67-
eval("__webpack_require__(636);\n\nvar universal = __webpack_require__(184);\nvar h1 = document.createElement('h1');\nh1.innerHTML = universal();\n\ndocument.body.appendChild(h1);\n\n\n//# sourceURL=webpack:///./example.js?");
71+
__webpack_require__(636);
72+
73+
var universal = __webpack_require__(184);
74+
var h1 = document.createElement('h1');
75+
h1.innerHTML = universal();
76+
77+
document.body.appendChild(h1);
78+
6879
})();
6980

7081
/******/ })()
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<head><script defer="defer" src="bundle.js"></script><link href="styles.css" rel="stylesheet"></head>Hello World from backend2020-10-16T09:28:24.192Z<h2>Partial</h2><img src="0714810ae3fb211173e2964249507195.png">
1+
<head><script defer="defer" src="bundle.js"></script><link href="styles.css" rel="stylesheet"></head>Hello World from backend2020-12-04T21:57:14.592Z<h2>Partial</h2><img src="55b19870aff2e53d1fb1.png">

examples/javascript/webpack.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ module.exports = {
77
entry: './example.js',
88
output: {
99
path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion),
10-
publicPath: '',
1110
filename: 'bundle.js'
1211
},
1312
module: {
1413
rules: [
1514
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
16-
{ test: /\.png$/, loader: 'file-loader' },
15+
{ test: /\.png$/, type: 'asset/resource' },
1716
{ test: /\.html$/, loader: 'html-loader' }
1817
]
1918
},
20-
devtool: 'eval',
2119
plugins: [
2220
new HtmlWebpackPlugin({
2321
template: 'template.js'

lib/child-compiler.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ class HtmlWebpackChildCompiler {
8888

8989
const outputOptions = {
9090
filename: '__child-[name]',
91-
publicPath: mainCompilation.outputOptions.publicPath,
91+
publicPath: mainCompilation.outputOptions.publicPath === 'auto'
92+
? ''
93+
: mainCompilation.outputOptions.publicPath,
9294
library: {
9395
type: 'var',
9496
name: 'HTML_WEBPACK_PLUGIN_RESULT'

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"style-loader": "0.23.1",
4949
"typescript": "4.0.5",
5050
"webpack": "5.10.0",
51-
"webpack-recompilation-simulator": "3.2.0"
51+
"webpack-recompilation-simulator": "3.2.0",
52+
"webpack-cli": "4.2.0"
5253
},
5354
"dependencies": {
5455
"@types/html-minifier-terser": "^5.0.0",

0 commit comments

Comments
 (0)