Skip to content

Commit 6bf471c

Browse files
refactor: use logger to avoid pulling logs in output (#1805)
1 parent 57c5a4e commit 6bf471c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ const path = require('path');
1010
const { CachedChildCompilation } = require('./lib/cached-child-compiler');
1111

1212
const { createHtmlTagObject, htmlTagObjectToString, HtmlTagArray } = require('./lib/html-tags');
13-
1413
const prettyError = require('./lib/errors.js');
1514
const chunkSorter = require('./lib/chunksorter.js');
1615
const getHtmlWebpackPluginHooks = require('./lib/hooks.js').getHtmlWebpackPluginHooks;
17-
const { assert } = require('console');
1816

1917
/** @typedef {import("./typings").HtmlTagObject} HtmlTagObject */
2018
/** @typedef {import("./typings").Options} HtmlWebpackOptions */
@@ -35,6 +33,8 @@ class HtmlWebpackPlugin {
3533
}
3634

3735
apply (compiler) {
36+
this.logger = compiler.getInfrastructureLogger('HtmlWebpackPlugin');
37+
3838
// Wait for configuration preset plugions to apply all configure webpack defaults
3939
compiler.hooks.initialize.tap('HtmlWebpackPlugin', () => {
4040
const userOptions = this.userOptions;
@@ -69,8 +69,13 @@ class HtmlWebpackPlugin {
6969
this.options = options;
7070

7171
// Assert correct option spelling
72-
assert(options.scriptLoading === 'defer' || options.scriptLoading === 'blocking' || options.scriptLoading === 'module', 'scriptLoading needs to be set to "defer", "blocking" or "module"');
73-
assert(options.inject === true || options.inject === false || options.inject === 'head' || options.inject === 'body', 'inject needs to be set to true, false, "head" or "body');
72+
if (options.scriptLoading !== 'defer' && options.scriptLoading !== 'blocking' && options.scriptLoading !== 'module') {
73+
this.logger.error('The "scriptLoading" option need to be set to "defer", "blocking" or "module"');
74+
}
75+
76+
if (options.inject !== true && options.inject !== false && options.inject !== 'head' && options.inject !== 'body') {
77+
this.logger.error('The `inject` option needs to be set to true, false, "head" or "body');
78+
}
7479

7580
// Default metaOptions if no template is provided
7681
if (!userOptions.template && options.templateContent === false && options.meta) {
@@ -419,7 +424,7 @@ function hookIntoCompiler (compiler, options, plugin) {
419424
outputName: finalOutputName,
420425
plugin: plugin
421426
}).catch(err => {
422-
console.error(err);
427+
plugin.logger.error(err);
423428
return null;
424429
}).then(() => null));
425430

lib/cached-child-compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
});
2222
* ```
2323
*/
24+
'use strict';
2425

2526
// Import types
2627
/** @typedef {import("webpack/lib/Compiler.js")} WebpackCompiler */
@@ -35,7 +36,6 @@
3536
dependencies: FileDependencies,
3637
error: Error
3738
}} ChildCompilationResult */
38-
'use strict';
3939

4040
const { HtmlWebpackChildCompiler } = require('./child-compiler');
4141
const fileWatcherApi = require('./file-watcher-api');

0 commit comments

Comments
 (0)