Skip to content

Commit

Permalink
Added silent option to loadLanguages (#2147)
Browse files Browse the repository at this point in the history
This adds an option to `loadLanguages` which prevents all warning messages.
  • Loading branch information
RunDevelopment committed Jan 6, 2020
1 parent 1fbac16 commit 191b411
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion components/index.js
Expand Up @@ -30,7 +30,9 @@ function loadLanguages(languages) {

getLoader(components, languages, loaded).load(lang => {
if (!(lang in components.languages)) {
console.warn('Language does not exist: ' + lang);
if (!loadLanguages.silent) {
console.warn('Language does not exist: ' + lang);
}
return;
}

Expand All @@ -46,4 +48,9 @@ function loadLanguages(languages) {
});
}

/**
* Set this to `true` to prevent all warning messages `loadLanguages` logs.
*/
loadLanguages.silent = false;

module.exports = loadLanguages;
2 changes: 2 additions & 0 deletions index.html
Expand Up @@ -226,6 +226,8 @@ <h2>Usage with Node</h2>

<p><strong>Note</strong>: Do <em>not</em> use <code class="language-javascript">loadLanguages()</code> with Webpack or another bundler, as this will cause Webpack to include all languages and plugins. Use the babel plugin described above.</p>

<p><strong>Note</strong>: <code class="language-javascript">loadLanguages()</code> will ignore unknown languages and log warning messages to the console. You can prevent the warnings by setting <code class="language-javascript">loadLanguages.silent = true</code>.</p>

</section>

<section class="language-markup">
Expand Down

0 comments on commit 191b411

Please sign in to comment.