Skip to content

Commit

Permalink
fix(.eslintrc,hotModuleReplacement.js): Update linting rules, no arro…
Browse files Browse the repository at this point in the history
…ws (#85)

* fix(.eslintrc,hotModuleReplacement.js): Update linting rules, remove arrow functions

Arrow functions break IE11 (whats new), updated eslint so it wont autofix it

fix #83

* style: Updated linting rules

No destructuring for IE

* fix: ES6 strings not TL

Dont use template literals
  • Loading branch information
ScriptedAlchemy committed Jul 16, 2018
1 parent 87334cf commit 58966be
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
41 changes: 22 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
generators: true,
experimentalObjectRestSpread: true
},
sourceType: 'module',
allowImportExportEverywhere: false
},
extends: ['airbnb'],
env: {
'browser': true,
},
rules: {
'no-param-reassign': 0,
'func-names': 0,
'no-underscore-dangle': 0,
'no-restricted-syntax': 0,
}
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
generators: true,
experimentalObjectRestSpread: true
},
sourceType: 'module',
allowImportExportEverywhere: false
},
extends: ['airbnb'],
env: {
'browser': true,
},
rules: {
'no-param-reassign': 0,
'func-names': 0,
'no-underscore-dangle': 0,
'no-restricted-syntax': 0,
'prefer-arrow-callback': 0,
'prefer-destructuring': 0,
'prefer-template': 0
}
};
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ NOTE: We have aligned out loader implementation to be the same as `mini-css-extr

**If you already use `mini-css-extract-plugin`, then you can just change the `require` statement - it's that easy**


**DONT USE THIS INSTALL CMD IF YOU ARE BETA TESTING:**
```
yarn add --dev extract-css-chunks-webpack-plugin
```
Expand Down
26 changes: 13 additions & 13 deletions src/hotModuleReplacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const srcByModuleId = Object.create(null);
const debounce = require('lodash/debounce');

const noDocument = typeof document === 'undefined';
const { forEach } = Array.prototype;
const forEach = Array.prototype.forEach;

const noop = function () {};

Expand All @@ -13,13 +13,13 @@ const getCurrentScriptUrl = function (moduleId) {

if (!src) {
if (document.currentScript) {
src = document.currentScript.src; // eslint-disable-line prefer-destructuring
src = document.currentScript.src;
} else {
const scripts = document.getElementsByTagName('script');
const lastScriptTag = scripts[scripts.length - 1];

if (lastScriptTag) {
src = lastScriptTag.src; // eslint-disable-line prefer-destructuring
src = lastScriptTag.src;
}
}
srcByModuleId[moduleId] = src;
Expand All @@ -31,10 +31,10 @@ const getCurrentScriptUrl = function (moduleId) {
if (!filename) {
return [src.replace('.js', '.css')];
}
return fileMap.split(',').map((mapRule) => {
const reg = new RegExp(`${filename}\\.js$`, 'g');
return fileMap.split(',').map(function (mapRule) {
const reg = new RegExp(filename + '\\.js$', 'g');
return normalizeUrl(
src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`),
src.replace(reg, mapRule.replace(/{fileName}/g, filename) + '.css'),
{ stripWWW: false },
);
});
Expand All @@ -43,7 +43,7 @@ const getCurrentScriptUrl = function (moduleId) {

function updateCss(el, url) {
if (!url) {
[url] = el.href.split('?');
url = el.href.split('?')[0];
}
if (el.isLoaded === false) {
// We seem to be about to replace a css link that hasn't loaded yet.
Expand All @@ -56,23 +56,23 @@ function updateCss(el, url) {
const newEl = el.cloneNode();

newEl.isLoaded = false;
newEl.addEventListener('load', () => {
newEl.addEventListener('load', function () {
newEl.isLoaded = true;
el.remove();
});
newEl.addEventListener('error', () => {
newEl.addEventListener('error', function () {
newEl.isLoaded = true;
el.remove();
});

newEl.href = `${url}?${Date.now()}`;
newEl.href = url + '?' + Date.now();
el.parentNode.appendChild(newEl);
}

function getReloadUrl(href, src) {
href = normalizeUrl(href, { stripWWW: false });
let ret;
src.some((url) => { // eslint-disable-line array-callback-return
src.some(function (url) { // eslint-disable-line array-callback-return
if (href.indexOf(src) > -1) {
ret = url;
}
Expand All @@ -84,7 +84,7 @@ function reloadStyle(src) { // eslint-disable-line no-unused-vars
const elements = document.querySelectorAll('link');
let loaded = false;

forEach.call(elements, (el) => {
forEach.call(elements, function (el) {
if (el.visited === true) return;

const url = getReloadUrl(el.href, src);
Expand All @@ -99,7 +99,7 @@ function reloadStyle(src) { // eslint-disable-line no-unused-vars

function reloadAll() {
const elements = document.querySelectorAll('link');
forEach.call(elements, (el) => {
forEach.call(elements, function (el) {
if (el.visited === true) return;
updateCss(el);
});
Expand Down

0 comments on commit 58966be

Please sign in to comment.