Skip to content

Commit e47ab3c

Browse files
feat: added insert option
1 parent 2d221cb commit e47ab3c

File tree

23 files changed

+1318
-1160
lines changed

23 files changed

+1318
-1160
lines changed

package-lock.json

+283-1,155
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"npm-run-all": "^4.1.5",
7676
"prettier": "^2.1.2",
7777
"standard-version": "^9.0.0",
78-
"webpack": "^4.44.2",
78+
"webpack": "^5.0.0-rc.5",
7979
"webpack-cli": "^3.3.6",
8080
"webpack-dev-server": "^3.7.2"
8181
},

src/CssLoadingRuntimeModule.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ const getCssChunkObject = (mainChunk, compilation) => {
2727
};
2828

2929
module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
30-
constructor(runtimeRequirements) {
30+
constructor(runtimeRequirements, insert) {
3131
super('css loading', 10);
3232
this.runtimeRequirements = runtimeRequirements;
33+
this.insert = insert;
3334
}
3435

3536
generate() {
@@ -77,8 +78,7 @@ module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
7778
'}',
7879
])
7980
: '',
80-
'var head = document.getElementsByTagName("head")[0];',
81-
'head.appendChild(linkTag);',
81+
this.insert,
8282
'return linkTag;',
8383
]
8484
)};`,

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ class MiniCssExtractPlugin {
443443
true
444444
)
445445
);
446-
compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set));
446+
compilation.addRuntimeModule(
447+
chunk,
448+
new CssLoadingRuntimeModule(set, this.options.insert)
449+
);
447450
};
448451
compilation.hooks.runtimeRequirementInTree
449452
.for(webpack.RuntimeGlobals.ensureChunkHandlers)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(self["webpackChunk"] = self["webpackChunk"] || []).push([[1],[
2+
/* 0 */,
3+
/* 1 */
4+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
5+
6+
"use strict";
7+
__webpack_require__.r(__webpack_exports__);
8+
// extracted by mini-css-extract-plugin
9+
10+
11+
/***/ })
12+
]]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
/******/ (() => { // webpackBootstrap
2+
/******/ var __webpack_modules__ = ({});
3+
/************************************************************************/
4+
/******/ // The module cache
5+
/******/ var __webpack_module_cache__ = {};
6+
/******/
7+
/******/ // The require function
8+
/******/ function __webpack_require__(moduleId) {
9+
/******/ // Check if module is in cache
10+
/******/ if(__webpack_module_cache__[moduleId]) {
11+
/******/ return __webpack_module_cache__[moduleId].exports;
12+
/******/ }
13+
/******/ // Create a new module (and put it into the cache)
14+
/******/ var module = __webpack_module_cache__[moduleId] = {
15+
/******/ // no module.id needed
16+
/******/ // no module.loaded needed
17+
/******/ exports: {}
18+
/******/ };
19+
/******/
20+
/******/ // Execute the module function
21+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
22+
/******/
23+
/******/ // Return the exports of the module
24+
/******/ return module.exports;
25+
/******/ }
26+
/******/
27+
/******/ // expose the modules object (__webpack_modules__)
28+
/******/ __webpack_require__.m = __webpack_modules__;
29+
/******/
30+
/************************************************************************/
31+
/******/ /* webpack/runtime/ensure chunk */
32+
/******/ (() => {
33+
/******/ __webpack_require__.f = {};
34+
/******/ // This file contains only the entry chunk.
35+
/******/ // The chunk loading function for additional chunks
36+
/******/ __webpack_require__.e = (chunkId) => {
37+
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
38+
/******/ __webpack_require__.f[key](chunkId, promises);
39+
/******/ return promises;
40+
/******/ }, []));
41+
/******/ };
42+
/******/ })();
43+
/******/
44+
/******/ /* webpack/runtime/get javascript chunk filename */
45+
/******/ (() => {
46+
/******/ // This function allow to reference async chunks
47+
/******/ __webpack_require__.u = (chunkId) => {
48+
/******/ // return url for filenames based on template
49+
/******/ return "" + chunkId + ".js";
50+
/******/ };
51+
/******/ })();
52+
/******/
53+
/******/ /* webpack/runtime/get mini-css chunk filename */
54+
/******/ (() => {
55+
/******/ // This function allow to reference all chunks
56+
/******/ __webpack_require__.miniCssF = (chunkId) => {
57+
/******/ // return url for filenames not based on template
58+
/******/ if (chunkId === 1) return "1.css";
59+
/******/ // return url for filenames based on template
60+
/******/ return "" + "main" + ".css";
61+
/******/ };
62+
/******/ })();
63+
/******/
64+
/******/ /* webpack/runtime/global */
65+
/******/ (() => {
66+
/******/ __webpack_require__.g = (function() {
67+
/******/ if (typeof globalThis === 'object') return globalThis;
68+
/******/ try {
69+
/******/ return this || new Function('return this')();
70+
/******/ } catch (e) {
71+
/******/ if (typeof window === 'object') return window;
72+
/******/ }
73+
/******/ })();
74+
/******/ })();
75+
/******/
76+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
77+
/******/ (() => {
78+
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
79+
/******/ })();
80+
/******/
81+
/******/ /* webpack/runtime/load script */
82+
/******/ (() => {
83+
/******/ var inProgress = {};
84+
/******/ // data-webpack is not used as build has no uniqueName
85+
/******/ // loadScript function to load a script via script tag
86+
/******/ __webpack_require__.l = (url, done, key) => {
87+
/******/ if(inProgress[url]) { inProgress[url].push(done); return; }
88+
/******/ var script, needAttach;
89+
/******/ if(key !== undefined) {
90+
/******/ var scripts = document.getElementsByTagName("script");
91+
/******/ for(var i = 0; i < scripts.length; i++) {
92+
/******/ var s = scripts[i];
93+
/******/ if(s.getAttribute("src") == url) { script = s; break; }
94+
/******/ }
95+
/******/ }
96+
/******/ if(!script) {
97+
/******/ needAttach = true;
98+
/******/ script = document.createElement('script');
99+
/******/
100+
/******/ script.charset = 'utf-8';
101+
/******/ script.timeout = 120;
102+
/******/ if (__webpack_require__.nc) {
103+
/******/ script.setAttribute("nonce", __webpack_require__.nc);
104+
/******/ }
105+
/******/
106+
/******/ script.src = url;
107+
/******/ }
108+
/******/ inProgress[url] = [done];
109+
/******/ var onScriptComplete = (prev, event) => {
110+
/******/ // avoid mem leaks in IE.
111+
/******/ script.onerror = script.onload = null;
112+
/******/ clearTimeout(timeout);
113+
/******/ var doneFns = inProgress[url];
114+
/******/ delete inProgress[url];
115+
/******/ script.parentNode && script.parentNode.removeChild(script);
116+
/******/ doneFns && doneFns.forEach((fn) => fn(event));
117+
/******/ if(prev) return prev(event);
118+
/******/ }
119+
/******/ ;
120+
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
121+
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
122+
/******/ script.onload = onScriptComplete.bind(null, script.onload);
123+
/******/ needAttach && document.head.appendChild(script);
124+
/******/ };
125+
/******/ })();
126+
/******/
127+
/******/ /* webpack/runtime/make namespace object */
128+
/******/ (() => {
129+
/******/ // define __esModule on exports
130+
/******/ __webpack_require__.r = (exports) => {
131+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
132+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
133+
/******/ }
134+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
135+
/******/ };
136+
/******/ })();
137+
/******/
138+
/******/ /* webpack/runtime/publicPath */
139+
/******/ (() => {
140+
/******/ var scriptUrl;
141+
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
142+
/******/ var document = __webpack_require__.g.document;
143+
/******/ if (!scriptUrl && document) {
144+
/******/ if (document.currentScript)
145+
/******/ scriptUrl = document.currentScript.src
146+
/******/ if (!scriptUrl) {
147+
/******/ var scripts = document.getElementsByTagName("script");
148+
/******/ if(scripts.length) scriptUrl = scripts[scripts.length - 1].src
149+
/******/ }
150+
/******/ }
151+
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
152+
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
153+
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
154+
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
155+
/******/ __webpack_require__.p = scriptUrl;
156+
/******/ })();
157+
/******/
158+
/******/ /* webpack/runtime/css loading */
159+
/******/ (() => {
160+
/******/ var createStylesheet = (fullhref, resolve, reject) => {
161+
/******/ var linkTag = document.createElement("link");
162+
/******/ linkTag.rel = "stylesheet";
163+
/******/ linkTag.type = "text/css";
164+
/******/ linkTag.onload = resolve;
165+
/******/ linkTag.onerror = function(event) {
166+
/******/ var request = event && event.target && event.target.src || fullhref;
167+
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
168+
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";
169+
/******/ err.request = request;
170+
/******/ linkTag.parentNode.removeChild(linkTag)
171+
/******/ reject(err);
172+
/******/ };
173+
/******/ linkTag.href = fullhref;
174+
/******/
175+
/******/ function insert(linkTag) {
176+
/******/ const reference = document.querySelector('.hot-reload');
177+
/******/
178+
/******/ if (reference) {
179+
/******/ reference.parentNode.insertBefore(linkTag, reference);
180+
/******/ }
181+
/******/ }
182+
/******/ insert(linkTag);
183+
/******/ return linkTag;
184+
/******/ };
185+
/******/ var findStylesheet = (href, fullhref) => {
186+
/******/ var existingLinkTags = document.getElementsByTagName("link");
187+
/******/ for(var i = 0; i < existingLinkTags.length; i++) {
188+
/******/ var tag = existingLinkTags[i];
189+
/******/ var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");
190+
/******/ if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return tag;
191+
/******/ }
192+
/******/ var existingStyleTags = document.getElementsByTagName("style");
193+
/******/ for(var i = 0; i < existingStyleTags.length; i++) {
194+
/******/ var tag = existingStyleTags[i];
195+
/******/ var dataHref = tag.getAttribute("data-href");
196+
/******/ if(dataHref === href || dataHref === fullhref) return tag;
197+
/******/ }
198+
/******/ };
199+
/******/ var loadStylesheet = (chunkId) => {
200+
/******/ return new Promise((resolve, reject) => {
201+
/******/ var href = __webpack_require__.miniCssF(chunkId);
202+
/******/ var fullhref = __webpack_require__.p + href;
203+
/******/ if(findStylesheet(href, fullhref)) return resolve();
204+
/******/ createStylesheet(fullhref, resolve, reject);
205+
/******/ });
206+
/******/ }
207+
/******/ // object to store loaded CSS chunks
208+
/******/ var installedCssChunks = {
209+
/******/ 0: 0
210+
/******/ };
211+
/******/
212+
/******/ __webpack_require__.f.miniCss = (chunkId, promises) => {
213+
/******/ var cssChunks = {"1":1};
214+
/******/ if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);
215+
/******/ else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {
216+
/******/ promises.push(installedCssChunks[chunkId] = loadStylesheet(chunkId).then(() => {
217+
/******/ installedCssChunks[chunkId] = 0;
218+
/******/ }, (e) => {
219+
/******/ delete installedCssChunks[chunkId];
220+
/******/ throw e;
221+
/******/ }));
222+
/******/ }
223+
/******/ };
224+
/******/
225+
/******/ // no hmr
226+
/******/ })();
227+
/******/
228+
/******/ /* webpack/runtime/jsonp chunk loading */
229+
/******/ (() => {
230+
/******/ // no baseURI
231+
/******/
232+
/******/ // object to store loaded and loading chunks
233+
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
234+
/******/ // Promise = chunk loading, 0 = chunk loaded
235+
/******/ var installedChunks = {
236+
/******/ 0: 0
237+
/******/ };
238+
/******/
239+
/******/
240+
/******/ __webpack_require__.f.j = (chunkId, promises) => {
241+
/******/ // JSONP chunk loading for javascript
242+
/******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
243+
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
244+
/******/
245+
/******/ // a Promise means "currently loading".
246+
/******/ if(installedChunkData) {
247+
/******/ promises.push(installedChunkData[2]);
248+
/******/ } else {
249+
/******/ if(true) { // all chunks have JS
250+
/******/ // setup Promise in chunk cache
251+
/******/ var promise = new Promise((resolve, reject) => {
252+
/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject];
253+
/******/ });
254+
/******/ promises.push(installedChunkData[2] = promise);
255+
/******/
256+
/******/ // start chunk loading
257+
/******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
258+
/******/ // create error before stack unwound to get useful stacktrace later
259+
/******/ var error = new Error();
260+
/******/ var loadingEnded = (event) => {
261+
/******/ if(__webpack_require__.o(installedChunks, chunkId)) {
262+
/******/ installedChunkData = installedChunks[chunkId];
263+
/******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
264+
/******/ if(installedChunkData) {
265+
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
266+
/******/ var realSrc = event && event.target && event.target.src;
267+
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
268+
/******/ error.name = 'ChunkLoadError';
269+
/******/ error.type = errorType;
270+
/******/ error.request = realSrc;
271+
/******/ installedChunkData[1](error);
272+
/******/ }
273+
/******/ }
274+
/******/ };
275+
/******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId);
276+
/******/ } else installedChunks[chunkId] = 0;
277+
/******/ }
278+
/******/ }
279+
/******/ };
280+
/******/
281+
/******/ // no prefetching
282+
/******/
283+
/******/ // no preloaded
284+
/******/
285+
/******/ // no HMR
286+
/******/
287+
/******/ // no HMR manifest
288+
/******/
289+
/******/ // no deferred startup
290+
/******/
291+
/******/ // install a JSONP callback for chunk loading
292+
/******/ var webpackJsonpCallback = (data) => {
293+
/******/ var [chunkIds, moreModules, runtime] = data;
294+
/******/ // add "moreModules" to the modules object,
295+
/******/ // then flag all "chunkIds" as loaded and fire callback
296+
/******/ var moduleId, chunkId, i = 0, resolves = [];
297+
/******/ for(;i < chunkIds.length; i++) {
298+
/******/ chunkId = chunkIds[i];
299+
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
300+
/******/ resolves.push(installedChunks[chunkId][0]);
301+
/******/ }
302+
/******/ installedChunks[chunkId] = 0;
303+
/******/ }
304+
/******/ for(moduleId in moreModules) {
305+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
306+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
307+
/******/ }
308+
/******/ }
309+
/******/ if(runtime) runtime(__webpack_require__);
310+
/******/ parentChunkLoadingFunction(data);
311+
/******/ while(resolves.length) {
312+
/******/ resolves.shift()();
313+
/******/ }
314+
/******/
315+
/******/ }
316+
/******/
317+
/******/ var chunkLoadingGlobal = self["webpackChunk"] = self["webpackChunk"] || [];
318+
/******/ var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);
319+
/******/ chunkLoadingGlobal.push = webpackJsonpCallback;
320+
/******/ })();
321+
/******/
322+
/************************************************************************/
323+
/* eslint-env browser */
324+
325+
// eslint-disable-next-line
326+
__webpack_require__.e(/* import() */ 1).then(__webpack_require__.bind(__webpack_require__, 1));
327+
328+
/******/ })()
329+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background: red;
3+
}
4+

0 commit comments

Comments
 (0)