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 @@ mini-css-extract-plugin testcase - + - +
Initial CSS: Must be green
@@ -97,6 +97,6 @@

- + diff --git a/test/manual/src/index.js b/test/manual/src/index.js index f6d93735..8f0d1450 100644 --- a/test/manual/src/index.js +++ b/test/manual/src/index.js @@ -94,3 +94,11 @@ makeButton(".crossorigin", () => { __webpack_public_path__ = originalPublicPath; return promise; }); + +const worker = new Worker(new URL("./worker.js", import.meta.url)); + +worker.postMessage("test"); + +worker.addEventListener("message", (event) => { + console.log(`Received message from worker: ${event.data}`); +}); diff --git a/test/manual/src/worker.css b/test/manual/src/worker.css new file mode 100644 index 00000000..90439bac --- /dev/null +++ b/test/manual/src/worker.css @@ -0,0 +1,3 @@ +body { + background: green; +} diff --git a/test/manual/src/worker.js b/test/manual/src/worker.js new file mode 100644 index 00000000..3edbc7a6 --- /dev/null +++ b/test/manual/src/worker.js @@ -0,0 +1,15 @@ +import "./worker.css"; + +// eslint-disable-next-line no-undef +self.onmessage = (event) => { + console.log(`Received message from application: ${event.data}`); + + // eslint-disable-next-line no-undef + self.postMessage("I'm alive!"); +}; + +async function load() { + return import("./simple.css"); +} + +load(); diff --git a/test/manual/webpack.config.js b/test/manual/webpack.config.js index 3892d04a..d4da523c 100644 --- a/test/manual/webpack.config.js +++ b/test/manual/webpack.config.js @@ -12,11 +12,15 @@ const ENABLE_ES_MODULE = : true; const OLD_API = - typeof process.env.OLD_API !== "undefined" ? yn(process.env.OLD_API) : true; + typeof process.env.OLD_API !== "undefined" ? yn(process.env.OLD_API) : false; -console.log(OLD_API); +console.log("OPTIONS:"); +console.log("ENABLE_HMR:", ENABLE_HMR); +console.log("ENABLE_ES_MODULE:", ENABLE_ES_MODULE); +console.log("OLD_API:", OLD_API); module.exports = { + devtool: false, mode: "development", output: { chunkFilename: "[name].chunk.js",