Skip to content
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

hmr support #100

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"node": ">= 6.11.5"
},
"peerDependencies": {
"style-loader": "^0.20.3",
"webpack": "^4.4.0"
},
"pre-commit": "lint-staged",
Expand Down
8 changes: 7 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import NodeTargetPlugin from 'webpack/lib/node/NodeTargetPlugin';
import LibraryTemplatePlugin from 'webpack/lib/LibraryTemplatePlugin';
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
import LimitChunkCountPlugin from 'webpack/lib/optimize/LimitChunkCountPlugin';
import styleLoader from 'style-loader';

const NS = path.dirname(fs.realpathSync(__filename));

Expand All @@ -25,8 +26,13 @@ const findModuleById = (modules, id) => {
return null;
};

export function pitch(request) {
export function pitch(request) { // eslint-disable-line consistent-return
const query = loaderUtils.getOptions(this) || {};

if (query.hmr !== false) {
return styleLoader.pitch(request);
}

const loaders = this.loaders.slice(this.loaderIndex + 1);
this.addDependency(this.resourcePath);
const childFilename = '*'; // eslint-disable-line no-path-concat
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7436,6 +7436,13 @@ strip-json-comments@^2.0.1, strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"

style-loader@^0.20.3:
version "0.20.3"
resolved "https://registry.yarnpkg.com/style-loader/-/style-loader-0.20.3.tgz#ebef06b89dec491bcb1fdb3452e913a6fd1c10c4"
dependencies:
loader-utils "^1.1.0"
schema-utils "^0.4.5"

suffix@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/suffix/-/suffix-0.1.0.tgz#3e46966de56af17600385e58db8ec659dd797907"
Expand Down