Skip to content

feat(hotLoading): Addressing some issues in HMR #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
{
"presets": [
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": "6.11.5",
"browsers": "cover 99.5%"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
],
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
]
}
}
"presets": [
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": "6.9.0"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
],
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
]
}
}
}
35 changes: 12 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
generators: true,
experimentalObjectRestSpread: true
},
sourceType: 'module',
allowImportExportEverywhere: false
},
extends: ['airbnb'],
env: {
'browser': true,
root: true,
plugins: ['prettier'],
extends: ['@webpack-contrib/eslint-config-webpack'],
globals: {
document: true
},
rules: {
'no-param-reassign': 0,
'func-names': 0,
'no-underscore-dangle': 0,
'no-restricted-syntax': 0,
'prefer-arrow-callback': 0,
'prefer-destructuring': 0,
'array-callback-return': 0,
'prefer-template': 0,
'class-methods-use-this': 0,
'no-plusplus': 0
}
'prettier/prettier': [
'error',
{ singleQuote: true, trailingComma: 'es5', arrowParens: 'always' },
],
'class-methods-use-this': 'off',
'no-undefined': 'off',
},
};
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ node_js:
script:
- echo success
after_success:
- npx semantic-release
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
Expand Down
32 changes: 32 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable */
const Configuration = {
extends: ['@commitlint/config-conventional'],

rules: {
'body-leading-blank': [1, 'always'],
'footer-leading-blank': [1, 'always'],
'header-max-length': [2, 'always', 72],
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [2, 'always', [
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
],
],
},
};

module.exports = Configuration;
14 changes: 3 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
testPathIgnorePatterns: [
'<rootDir>/TO_DELETE_test/',
],
transformIgnorePatterns: [
'/node_modules/',
'<rootDir>/dist/',
],
watchPathIgnorePatterns: [
'<rootDir>/test/js',
],
testURL: 'http://localhost/',
transformIgnorePatterns: ['/node_modules/', '<rootDir>/dist/'],
watchPathIgnorePatterns: ['<rootDir>/test/js'],
};

32 changes: 14 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,52 +46,48 @@
"ci:coverage": "npm run test:coverage -- --runInBand",
"build:example": "npm run build && webpack-dev-server test/manual/src/index.js --open --config test/manual/webpack.config.js",
"cm": "git-cz",
"release": "standard-version",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"travis": "npm run ci:coverage"
"semantic-release": "npx semantic-release pre && npm publish && npx semantic-release post",
"travis": "npm run ci:coverage",
"defaults": "webpack-defaults"
},
"peerDependencies": {
"webpack": "^4.8.3"
"webpack": "^4.4.0"
},
"dependencies": {
"loader-utils": "^1.1.0",
"lodash": "^4.17.5",
"normalize-url": "^1.9.1",
"lodash": "^4.17.11",
"normalize-url": "^4.1.0",
"schema-utils": "^1.0.0",
"webpack-sources": "^1.1.0"
},
"devDependencies": {
"@commitlint/cli": "^6.1.3",
"@commitlint/config-conventional": "^6.1.3",
"@webpack-contrib/eslint-config-webpack": "^2.0.4",
"babel-cli": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-jest": "^22.2.2",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"commitizen": "^2.10.1",
"conventional-github-releaser": "^2.0.2",
"cross-env": "^5.1.3",
"css-loader": "^0.28.10",
"cz-conventional-changelog": "^2.1.0",
"del": "^3.0.0",
"del-cli": "^1.1.0",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-flowtype": "^2.32.1",
"eslint": "^4.17.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.0.1",
"file-loader": "^1.1.11",
"husky": "^0.14.3",
"jest": "^22.2.2",
"lint-staged": "^6.1.0",
"memory-fs": "^0.4.1",
"nsp": "^3.1.0",
"pre-commit": "^1.2.2",
"prettier": "^1.11.1",
"standard-version": "^4.4.0",
"semantic-release": "^6.3.2",
"webpack": "4.8.3",
"webpack": "^4.14.0",
"webpack-cli": "^2.0.13",
"webpack-defaults": "^2.3.0",
"webpack-dev-server": "^3.1.1"
},
"homepage": "http://github.com/faceyspacey/extract-css-chunks-webpack-plugin",
Expand Down
23 changes: 14 additions & 9 deletions src/hotLoader.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
const path = require('path');

const loaderUtils = require('loader-utils');

const defaultOptions = {
fileMap: '{fileName}',
cssModules: true,
fileMap: '{fileName}',
};

module.exports = function (content) {
this.cacheable();
const options = Object.assign(
module.exports = function(content) {
this.cacheable();
const options = Object.assign(
{},
defaultOptions,
loaderUtils.getOptions(this),
loaderUtils.getOptions(this)
);

const accept = options.cssModules ? '' : 'module.hot.accept(undefined, cssReload);';
return content + `
const accept = options.cssModules
? ''
: 'module.hot.accept(undefined, cssReload);';
return `${content}
if(module.hot) {
// ${Date.now()}
var cssReload = require(${loaderUtils.stringifyRequest(this, path.join(__dirname, 'hotModuleReplacement.js'))})(module.id, ${JSON.stringify(options)});
var cssReload = require(${loaderUtils.stringifyRequest(
this,
path.join(__dirname, 'hotModuleReplacement.js')
)})(module.id, ${JSON.stringify(options)});
module.hot.dispose(cssReload);
${accept};
}
Expand Down
Loading