From b09b439f50ecb75994acde2eb2967ad690ff1cf0 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Fri, 4 Dec 2020 22:53:06 +0100 Subject: [PATCH] fix: add support for publicPath: 'auto' in combination with type: 'asset/resource' --- ...249507195.png => 55b19870aff2e53d1fb1.png} | Bin examples/javascript/dist/webpack-5/bundle.js | 33 ++++++++++++------ examples/javascript/dist/webpack-5/index.html | 2 +- examples/javascript/webpack.config.js | 4 +-- lib/child-compiler.js | 4 ++- package.json | 3 +- 6 files changed, 29 insertions(+), 17 deletions(-) rename examples/javascript/dist/webpack-5/{0714810ae3fb211173e2964249507195.png => 55b19870aff2e53d1fb1.png} (100%) diff --git a/examples/javascript/dist/webpack-5/0714810ae3fb211173e2964249507195.png b/examples/javascript/dist/webpack-5/55b19870aff2e53d1fb1.png similarity index 100% rename from examples/javascript/dist/webpack-5/0714810ae3fb211173e2964249507195.png rename to examples/javascript/dist/webpack-5/55b19870aff2e53d1fb1.png diff --git a/examples/javascript/dist/webpack-5/bundle.js b/examples/javascript/dist/webpack-5/bundle.js index f792c431..19f621e1 100644 --- a/examples/javascript/dist/webpack-5/bundle.js +++ b/examples/javascript/dist/webpack-5/bundle.js @@ -1,11 +1,3 @@ -/* - * 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__ = ({ @@ -13,7 +5,17 @@ /***/ ((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'); +}; + /***/ }), @@ -21,7 +23,9 @@ eval("// This file is used for frontend and backend\n\n\n// If compiled by the h /***/ ((__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 + /***/ }) @@ -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); + })(); /******/ })() diff --git a/examples/javascript/dist/webpack-5/index.html b/examples/javascript/dist/webpack-5/index.html index c6d341ce..ba9876f7 100644 --- a/examples/javascript/dist/webpack-5/index.html +++ b/examples/javascript/dist/webpack-5/index.html @@ -1 +1 @@ -Hello World from backend2020-10-16T09:28:24.192Z

Partial

\ No newline at end of file +Hello World from backend2020-12-04T21:57:14.592Z

Partial

\ No newline at end of file diff --git a/examples/javascript/webpack.config.js b/examples/javascript/webpack.config.js index 510a462f..9945c4c5 100644 --- a/examples/javascript/webpack.config.js +++ b/examples/javascript/webpack.config.js @@ -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' diff --git a/lib/child-compiler.js b/lib/child-compiler.js index e94bec38..1b7cbaab 100644 --- a/lib/child-compiler.js +++ b/lib/child-compiler.js @@ -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' diff --git a/package.json b/package.json index 248f9186..277b8ad5 100644 --- a/package.json +++ b/package.json @@ -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",