-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: lazy load the plugin config file
- Loading branch information
Showing
62 changed files
with
410 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const path = require('path'); | ||
|
||
class Config { | ||
static #loaded = false; | ||
static #configFile = ''; | ||
static #config = { | ||
// plugin name, must be same as node module name | ||
pluginName: 'webpack-plugin', | ||
// label in terminal output from plugin | ||
pluginLabel: 'plugin', | ||
// label in terminal output from loader | ||
loaderLabel: 'loader', | ||
}; | ||
|
||
static init(file) { | ||
this.#configFile = path.isAbsolute(file) | ||
? require.resolve(file) | ||
: // path relative to `./src/Common` | ||
require.resolve(path.join('../', file)); | ||
} | ||
|
||
static get() { | ||
// lazy load config data | ||
if (!this.#loaded) { | ||
this.#load(); | ||
} | ||
|
||
return this.#config; | ||
} | ||
|
||
static #load() { | ||
if (this.#configFile) { | ||
let config = require(this.#configFile); | ||
this.#config = Object.assign(this.#config, config); | ||
this.#loaded = true; | ||
} | ||
} | ||
} | ||
|
||
module.exports = Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
const pluginName = 'html-bundler-webpack-plugin'; | ||
|
||
module.exports = { | ||
pluginName, | ||
// plugin name, must be same as node module name | ||
pluginName: 'html-bundler-webpack-plugin', | ||
// label in terminal output from plugin | ||
pluginLabel: 'HTML Bundler Plugin', | ||
// label in terminal output from loader | ||
loaderLabel: 'HTML Bundler Loader', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.