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

feat: add stats option #537

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -188,6 +188,13 @@ module.exports = {
};
```

### `stats`

Type: `String|Boolean`
Default: `'normal'`

The [logging preset](https://webpack.js.org/configuration/stats/#stats-presets) to use. Object syntax is unsupported at this time.

## Examples

### Minimal example
Expand Down
19 changes: 15 additions & 4 deletions src/hmr/hotModuleReplacement.js
Expand Up @@ -196,8 +196,19 @@ function isUrlRequest(url) {
}

module.exports = function(moduleId, options) {
// By default, log everything. For certain presets, do not log informational
// messages. See https://webpack.js.org/configuration/stats/#stats-presets.
const stats = options.stats === undefined ? 'normal' : options.stats; // eslint-disable-line no-undefined
const log =
stats === 'errors-only' ||
stats === 'errors-warnings' ||
stats === 'none' ||
stats === false
? () => {}
: console.log;

if (noDocument) {
console.log('no window.document found, will not HMR CSS');
log('no window.document found, will not HMR CSS');

return noop;
}
Expand All @@ -209,17 +220,17 @@ module.exports = function(moduleId, options) {
const reloaded = reloadStyle(src);

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

reloadAll();

return;
}

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

reloadAll();
}
Expand Down
10 changes: 10 additions & 0 deletions src/loader-options.json
Expand Up @@ -20,6 +20,16 @@
},
"reloadAll": {
"type": "boolean"
},
"stats": {
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
}
}
}