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 all commits
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
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -188,6 +188,14 @@ module.exports = {
};
```

### `clientLogLevel`

Type: `String`
Default: `'info'`

The browser console logging level as described by
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/#devserverclientloglevel).

## Examples

### Minimal example
Expand Down Expand Up @@ -301,6 +309,7 @@ module.exports = {
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
clientLogLevel: 'warn',
},
},
'css-loader',
Expand Down
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"loader-utils": "^1.1.0",
"loglevel": "^1.6.8",
"normalize-url": "1.9.1",
"schema-utils": "^1.0.0",
"webpack-sources": "^1.1.0"
Expand Down
15 changes: 11 additions & 4 deletions src/hmr/hotModuleReplacement.js
Expand Up @@ -6,6 +6,9 @@
*/

const normalizeUrl = require('normalize-url');
const logger = require('loglevel').getLogger('mini-css-extract-plugin');

logger.setDefaultLevel('info');

const srcByModuleId = Object.create(null);

Expand Down Expand Up @@ -196,8 +199,12 @@ function isUrlRequest(url) {
}

module.exports = function(moduleId, options) {
if (options.clientLogLevel) {
logger.setLevel(options.clientLogLevel);
}

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

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

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

reloadAll();

return;
}

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

reloadAll();
}
Expand Down
12 changes: 12 additions & 0 deletions src/loader-options.json
Expand Up @@ -20,6 +20,18 @@
},
"reloadAll": {
"type": "boolean"
},
"clientLogLevel": {
"enum": [
"info",
"warn",
"error",
"debug",
"trace",
"silent",
"none",
"warning"
]
}
}
}
42 changes: 42 additions & 0 deletions test/__snapshots__/validate-loader-options.test.js.snap
@@ -1,5 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validate options should throw an error on the "clientLogLevel" option with "{}" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

options.clientLogLevel should be equal to one of the allowed values
"
`;

exports[`validate options should throw an error on the "clientLogLevel" option with "0" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

options.clientLogLevel should be equal to one of the allowed values
"
`;

exports[`validate options should throw an error on the "clientLogLevel" option with "1" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

options.clientLogLevel should be equal to one of the allowed values
"
`;

exports[`validate options should throw an error on the "clientLogLevel" option with "false" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

options.clientLogLevel should be equal to one of the allowed values
"
`;

exports[`validate options should throw an error on the "clientLogLevel" option with "foo" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

options.clientLogLevel should be equal to one of the allowed values
"
`;

exports[`validate options should throw an error on the "clientLogLevel" option with "true" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

options.clientLogLevel should be equal to one of the allowed values
"
`;

exports[`validate options should throw an error on the "esModule" option with "1" value 1`] = `
"Mini CSS Extract Plugin Loader Invalid Options

Expand Down
13 changes: 13 additions & 0 deletions test/validate-loader-options.test.js
Expand Up @@ -18,6 +18,19 @@ describe('validate options', () => {
success: [true, false],
failure: [1],
},
clientLogLevel: {
success: [
'info',
'warn',
'error',
'debug',
'trace',
'silent',
'none',
'warning',
],
failure: [true, false, 'foo', 0, 1, {}],
},
unknown: {
success: [],
// TODO failed in next release
Expand Down