From 4d98d4b973be27910b84194e6f7acb1d09f1e8ae Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Tue, 6 Dec 2022 05:01:40 +0300 Subject: [PATCH] fix: don't crash in web workers (#1004) --- src/index.js | 1 + ...51f3fe3a0d0.css => 0.4568ffdcdfced785eabc.css} | 0 ...4f51f3fe3a0d0.css => 4568ffdcdfced785eabc.css} | 0 .../expected/webpack-5-importModule/main.js | 3 ++- ...411c41d8362.css => 0.9ee2d65d5d13f2b4323d.css} | 0 ...e7411c41d8362.css => 9ee2d65d5d13f2b4323d.css} | 0 .../expected/webpack-5/main.js | 3 ++- test/cases/hmr/expected/main.js | 1 + test/cases/insert-function/expected/main.js | 1 + test/cases/insert-string/expected/main.js | 1 + test/cases/insert-undefined/expected/main.js | 1 + test/manual/index.html | 6 +++--- test/manual/src/index.js | 8 ++++++++ test/manual/src/worker.css | 3 +++ test/manual/src/worker.js | 15 +++++++++++++++ test/manual/webpack.config.js | 8 ++++++-- 16 files changed, 44 insertions(+), 7 deletions(-) rename test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/{0.945622d4f51f3fe3a0d0.css => 0.4568ffdcdfced785eabc.css} (100%) rename test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/{945622d4f51f3fe3a0d0.css => 4568ffdcdfced785eabc.css} (100%) rename test/cases/chunkFilename-fullhash/expected/webpack-5/{0.de494c1e7411c41d8362.css => 0.9ee2d65d5d13f2b4323d.css} (100%) rename test/cases/chunkFilename-fullhash/expected/webpack-5/{de494c1e7411c41d8362.css => 9ee2d65d5d13f2b4323d.css} (100%) create mode 100644 test/manual/src/worker.css create mode 100644 test/manual/src/worker.js diff --git a/src/index.js b/src/index.js index 6f76879e..d89d4fa9 100644 --- a/src/index.js +++ b/src/index.js @@ -825,6 +825,7 @@ class MiniCssExtractPlugin { } return Template.asString([ + 'if (typeof document === "undefined") return;', `var createStylesheet = ${runtimeTemplate.basicFunction( "chunkId, fullhref, oldTag, resolve, reject", [ diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/0.945622d4f51f3fe3a0d0.css b/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/0.4568ffdcdfced785eabc.css similarity index 100% rename from test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/0.945622d4f51f3fe3a0d0.css rename to test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/0.4568ffdcdfced785eabc.css diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/945622d4f51f3fe3a0d0.css b/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/4568ffdcdfced785eabc.css similarity index 100% rename from test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/945622d4f51f3fe3a0d0.css rename to test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/4568ffdcdfced785eabc.css diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js b/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js index 8c4d255c..462b4287 100644 --- a/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js +++ b/test/cases/chunkFilename-fullhash/expected/webpack-5-importModule/main.js @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__); /******/ /******/ /* webpack/runtime/getFullHash */ /******/ (() => { -/******/ __webpack_require__.h = () => ("945622d4f51f3fe3a0d0") +/******/ __webpack_require__.h = () => ("4568ffdcdfced785eabc") /******/ })(); /******/ /******/ /* webpack/runtime/global */ @@ -171,6 +171,7 @@ __webpack_require__.r(__webpack_exports__); /******/ /******/ /* webpack/runtime/css loading */ /******/ (() => { +/******/ if (typeof document === "undefined") return; /******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => { /******/ var linkTag = document.createElement("link"); /******/ diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5/0.de494c1e7411c41d8362.css b/test/cases/chunkFilename-fullhash/expected/webpack-5/0.9ee2d65d5d13f2b4323d.css similarity index 100% rename from test/cases/chunkFilename-fullhash/expected/webpack-5/0.de494c1e7411c41d8362.css rename to test/cases/chunkFilename-fullhash/expected/webpack-5/0.9ee2d65d5d13f2b4323d.css diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5/de494c1e7411c41d8362.css b/test/cases/chunkFilename-fullhash/expected/webpack-5/9ee2d65d5d13f2b4323d.css similarity index 100% rename from test/cases/chunkFilename-fullhash/expected/webpack-5/de494c1e7411c41d8362.css rename to test/cases/chunkFilename-fullhash/expected/webpack-5/9ee2d65d5d13f2b4323d.css diff --git a/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js b/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js index 9cbf1619..68c828cc 100644 --- a/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js +++ b/test/cases/chunkFilename-fullhash/expected/webpack-5/main.js @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__); /******/ /******/ /* webpack/runtime/getFullHash */ /******/ (() => { -/******/ __webpack_require__.h = () => ("de494c1e7411c41d8362") +/******/ __webpack_require__.h = () => ("9ee2d65d5d13f2b4323d") /******/ })(); /******/ /******/ /* webpack/runtime/global */ @@ -171,6 +171,7 @@ __webpack_require__.r(__webpack_exports__); /******/ /******/ /* webpack/runtime/css loading */ /******/ (() => { +/******/ if (typeof document === "undefined") return; /******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => { /******/ var linkTag = document.createElement("link"); /******/ diff --git a/test/cases/hmr/expected/main.js b/test/cases/hmr/expected/main.js index eebf4011..581539a3 100644 --- a/test/cases/hmr/expected/main.js +++ b/test/cases/hmr/expected/main.js @@ -934,6 +934,7 @@ __webpack_require__.r(__webpack_exports__); /******/ /******/ /* webpack/runtime/css loading */ /******/ (() => { +/******/ if (typeof document === "undefined") return; /******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => { /******/ var linkTag = document.createElement("link"); /******/ diff --git a/test/cases/insert-function/expected/main.js b/test/cases/insert-function/expected/main.js index 0034d7cf..96349f1f 100644 --- a/test/cases/insert-function/expected/main.js +++ b/test/cases/insert-function/expected/main.js @@ -155,6 +155,7 @@ /******/ /******/ /* webpack/runtime/css loading */ /******/ (() => { +/******/ if (typeof document === "undefined") return; /******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => { /******/ var linkTag = document.createElement("link"); /******/ diff --git a/test/cases/insert-string/expected/main.js b/test/cases/insert-string/expected/main.js index 05e9aaeb..04dd03fd 100644 --- a/test/cases/insert-string/expected/main.js +++ b/test/cases/insert-string/expected/main.js @@ -155,6 +155,7 @@ /******/ /******/ /* webpack/runtime/css loading */ /******/ (() => { +/******/ if (typeof document === "undefined") return; /******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => { /******/ var linkTag = document.createElement("link"); /******/ diff --git a/test/cases/insert-undefined/expected/main.js b/test/cases/insert-undefined/expected/main.js index 907e94ad..ea87a2bc 100644 --- a/test/cases/insert-undefined/expected/main.js +++ b/test/cases/insert-undefined/expected/main.js @@ -155,6 +155,7 @@ /******/ /******/ /* webpack/runtime/css loading */ /******/ (() => { +/******/ if (typeof document === "undefined") return; /******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => { /******/ var linkTag = document.createElement("link"); /******/ diff --git a/test/manual/index.html b/test/manual/index.html index 610b7268..3b7d2ca4 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -5,7 +5,7 @@