Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack-contrib/mini-css-extract-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: boostmyschool/mini-css-extract-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Apr 20, 2020

  1. Copy the full SHA
    0007398 View commit details
  2. Copy the full SHA
    51d6d63 View commit details
Showing with 979 additions and 1 deletion.
  1. +0 −1 .gitignore
  2. +34 −0 dist/CssDependency.js
  3. +3 −0 dist/cjs.js
  4. +211 −0 dist/hmr/hotModuleReplacement.js
  5. +468 −0 dist/index.js
  6. +25 −0 dist/loader-options.json
  7. +203 −0 dist/loader.js
  8. +18 −0 dist/plugin-options.json
  9. +17 −0 src/index.js
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ logs
npm-debug.log*
.eslintcache
/coverage
/dist
/test/js
/local
/reports
34 changes: 34 additions & 0 deletions dist/CssDependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;

var _webpack = _interopRequireDefault(require("webpack"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

class CssDependency extends _webpack.default.Dependency {
constructor({
identifier,
content,
media,
sourceMap
}, context, identifierIndex) {
super();
this.identifier = identifier;
this.identifierIndex = identifierIndex;
this.content = content;
this.media = media;
this.sourceMap = sourceMap;
this.context = context;
}

getResourceIdentifier() {
return `css-module-${this.identifier}-${this.identifierIndex}`;
}

}

exports.default = CssDependency;
3 changes: 3 additions & 0 deletions dist/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

module.exports = require('./index').default;
211 changes: 211 additions & 0 deletions dist/hmr/hotModuleReplacement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
"use strict";

/* eslint-env browser */

/*
eslint-disable
no-console,
func-names
*/
var normalizeUrl = require('normalize-url');

var srcByModuleId = Object.create(null);
var noDocument = typeof document === 'undefined';
var forEach = Array.prototype.forEach;

function debounce(fn, time) {
var timeout = 0;
return function () {
var self = this; // eslint-disable-next-line prefer-rest-params

var args = arguments;

var functionCall = function functionCall() {
return fn.apply(self, args);
};

clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
};
}

function noop() {}

function getCurrentScriptUrl(moduleId) {
var src = srcByModuleId[moduleId];

if (!src) {
if (document.currentScript) {
src = document.currentScript.src;
} else {
var scripts = document.getElementsByTagName('script');
var lastScriptTag = scripts[scripts.length - 1];

if (lastScriptTag) {
src = lastScriptTag.src;
}
}

srcByModuleId[moduleId] = src;
}

return function (fileMap) {
if (!src) {
return null;
}

var splitResult = src.split(/([^\\/]+)\.js$/);
var filename = splitResult && splitResult[1];

if (!filename) {
return [src.replace('.js', '.css')];
}

if (!fileMap) {
return [src.replace('.js', '.css')];
}

return fileMap.split(',').map(function (mapRule) {
var reg = new RegExp("".concat(filename, "\\.js$"), 'g');
return normalizeUrl(src.replace(reg, "".concat(mapRule.replace(/{fileName}/g, filename), ".css")), {
stripWWW: false
});
});
};
}

function updateCss(el, url) {
if (!url) {
if (!el.href) {
return;
} // eslint-disable-next-line


url = el.href.split('?')[0];
}

if (!isUrlRequest(url)) {
return;
}

if (el.isLoaded === false) {
// We seem to be about to replace a css link that hasn't loaded yet.
// We're probably changing the same file more than once.
return;
}

if (!url || !(url.indexOf('.css') > -1)) {
return;
} // eslint-disable-next-line no-param-reassign


el.visited = true;
var newEl = el.cloneNode();
newEl.isLoaded = false;
newEl.addEventListener('load', function () {
newEl.isLoaded = true;
el.parentNode.removeChild(el);
});
newEl.addEventListener('error', function () {
newEl.isLoaded = true;
el.parentNode.removeChild(el);
});
newEl.href = "".concat(url, "?").concat(Date.now());

if (el.nextSibling) {
el.parentNode.insertBefore(newEl, el.nextSibling);
} else {
el.parentNode.appendChild(newEl);
}
}

function getReloadUrl(href, src) {
var ret; // eslint-disable-next-line no-param-reassign

href = normalizeUrl(href, {
stripWWW: false
}); // eslint-disable-next-line array-callback-return

src.some(function (url) {
if (href.indexOf(src) > -1) {
ret = url;
}
});
return ret;
}

function reloadStyle(src) {
var elements = document.querySelectorAll('link');
var loaded = false;
forEach.call(elements, function (el) {
if (!el.href) {
return;
}

var url = getReloadUrl(el.href, src);

if (!isUrlRequest(url)) {
return;
}

if (el.visited === true) {
return;
}

if (url) {
updateCss(el, url);
loaded = true;
}
});
return loaded;
}

function reloadAll() {
var elements = document.querySelectorAll('link');
forEach.call(elements, function (el) {
if (el.visited === true) {
return;
}

updateCss(el);
});
}

function isUrlRequest(url) {
// An URL is not an request if
// It is not http or https
if (!/^https?:/i.test(url)) {
return false;
}

return true;
}

module.exports = function (moduleId, options) {
if (noDocument) {
console.log('no window.document found, will not HMR CSS');
return noop;
}

var getScriptSrc = getCurrentScriptUrl(moduleId);

function update() {
var src = getScriptSrc(options.filename);
var reloaded = reloadStyle(src);

if (options.locals) {
console.log('[HMR] Detected local css modules. Reload all css');
reloadAll();
return;
}

if (reloaded && !options.reloadAll) {
console.log('[HMR] css reload %s', src.join(' '));
} else {
console.log('[HMR] Reload all css');
reloadAll();
}
}

return debounce(update, 50);
};
Loading