MCPcopy
hub / github.com/webpack/webpack / loadConfiguration

Function loadConfiguration

test/Examples.test.js:52–90  ·  view source on GitHub ↗

* @param {string} projectDir a project directory * @returns {Promise<EXPECTED_ANY | undefined>} webpack options

(projectDir)

Source from the content-addressed store, hash-verified

50 * @returns {Promise<EXPECTED_ANY | undefined>} webpack options
51 */
52async function loadConfiguration(projectDir) {
53 const paths = [
54 path.join(projectDir, "webpack.config.js"),
55 path.join(projectDir, "webpack.config.mjs"),
56 path.join(projectDir, "webpack.config.cjs")
57 ];
58
59 let options;
60
61 for (const path of paths) {
62 if (!fs.existsSync(path)) {
63 continue;
64 }
65
66 if (nodeVersion < 18) {
67 try {
68 options = require(path);
69 return options;
70 } catch (_err) {
71 // Nothing
72 }
73
74 return;
75 }
76
77 try {
78 options = await dynamicImport(path);
79 return options.default;
80 } catch (_err) {
81 try {
82 options = require(path);
83 } catch (_err) {
84 // Nothing
85 }
86 }
87 }
88
89 return options;
90}
91
92describe("Examples", () => {
93 const basePath = path.join(__dirname, "..", "examples");

Callers 1

Examples.test.jsFile · 0.85

Calls 1

requireFunction · 0.70

Tested by

no test coverage detected