Skip to content

Commit

Permalink
fix: add support for publicPath: 'auto' in combination with type: 'as…
Browse files Browse the repository at this point in the history
…set/resource'
  • Loading branch information
jantimon committed Feb 3, 2021
1 parent ab8b195 commit 0f9c239
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
33 changes: 22 additions & 11 deletions examples/javascript/dist/webpack-5/bundle.js
@@ -1,27 +1,31 @@
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is not neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 184:
/***/ ((module) => {

"use strict";
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?");
// This file is used for frontend and backend


// If compiled by the html-webpack-plugin
// HTML_WEBPACK_PLUGIN is set to true:
var backend = typeof HTML_WEBPACK_PLUGIN !== 'undefined';

module.exports = function () {
return 'Hello World from ' + (backend ? 'backend' : 'frontend');
};


/***/ }),

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

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


/***/ })

Expand Down Expand Up @@ -64,7 +68,14 @@ eval("__webpack_require__.r(__webpack_exports__);\n// extracted by mini-css-extr
/******/
/************************************************************************/
(() => {
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?");
__webpack_require__(636);

var universal = __webpack_require__(184);
var h1 = document.createElement('h1');
h1.innerHTML = universal();

document.body.appendChild(h1);

})();

/******/ })()
Expand Down
2 changes: 1 addition & 1 deletion examples/javascript/dist/webpack-5/index.html
@@ -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">
<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">
4 changes: 1 addition & 3 deletions examples/javascript/webpack.config.js
Expand Up @@ -7,17 +7,15 @@ module.exports = {
entry: './example.js',
output: {
path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion),
publicPath: '',
filename: 'bundle.js'
},
module: {
rules: [
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
{ test: /\.png$/, loader: 'file-loader' },
{ test: /\.png$/, type: 'asset/resource' },
{ test: /\.html$/, loader: 'html-loader' }
]
},
devtool: 'eval',
plugins: [
new HtmlWebpackPlugin({
template: 'template.js'
Expand Down
4 changes: 3 additions & 1 deletion lib/child-compiler.js
Expand Up @@ -88,7 +88,9 @@ class HtmlWebpackChildCompiler {

const outputOptions = {
filename: '__child-[name]',
publicPath: mainCompilation.outputOptions.publicPath,
publicPath: mainCompilation.outputOptions.publicPath === 'auto'
? ''
: mainCompilation.outputOptions.publicPath,
library: {
type: 'var',
name: 'HTML_WEBPACK_PLUGIN_RESULT'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -48,7 +48,8 @@
"style-loader": "0.23.1",
"typescript": "4.0.5",
"webpack": "5.10.0",
"webpack-recompilation-simulator": "3.2.0"
"webpack-recompilation-simulator": "3.2.0",
"webpack-cli": "4.2.0"
},
"dependencies": {
"@types/html-minifier-terser": "^5.0.0",
Expand Down

0 comments on commit 0f9c239

Please sign in to comment.