-
-
Notifications
You must be signed in to change notification settings - Fork 610
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: watch mode config change #2797
Changes from 1 commit
6d3ba0d
05703b0
bc1f853
ae86f43
bf73f5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,15 @@ class WebpackCLI { | |
), | ||
}); | ||
} | ||
|
||
async tryRequireThenImport(module, handleError = true) { | ||
let result; | ||
|
||
try { | ||
delete require.cache[module]; | ||
result = require(module); | ||
console.log(result); | ||
} catch (error) { | ||
console.log(error, "HEY"); | ||
let previousModuleCompile; | ||
|
||
// TODO Workaround https://github.com/zertosh/v8-compile-cache/issues/30 | ||
|
@@ -67,7 +69,6 @@ class WebpackCLI { | |
throw error; | ||
} | ||
} | ||
|
||
// For babel/typescript | ||
if (result.default) { | ||
result = result.default; | ||
|
@@ -1545,10 +1546,8 @@ class WebpackCLI { | |
|
||
process.exit(2); | ||
} | ||
|
||
return { options, path: configPath }; | ||
}; | ||
|
||
const evaluateConfig = async (loadedConfig, argv) => { | ||
const isMultiCompiler = Array.isArray(loadedConfig.options); | ||
const config = isMultiCompiler ? loadedConfig.options : [loadedConfig.options]; | ||
|
@@ -1581,7 +1580,7 @@ class WebpackCLI { | |
return loadedConfig; | ||
}; | ||
|
||
const config = { options: {}, path: new WeakMap() }; | ||
const config = { options: {}, path: new Map() }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're not using config.path anywhere, what's to leak? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at CLI plugin |
||
|
||
if (options.config && options.config.length > 0) { | ||
const evaluatedConfigs = await Promise.all( | ||
|
@@ -1638,9 +1637,7 @@ class WebpackCLI { | |
if (foundDefaultConfigFile) { | ||
const loadedConfig = await loadConfig(foundDefaultConfigFile.path); | ||
const evaluatedConfig = await evaluateConfig(loadedConfig, options.argv || {}); | ||
|
||
config.options = evaluatedConfig.options; | ||
|
||
if (Array.isArray(config.options)) { | ||
config.options.forEach((options) => { | ||
config.path.set(options, evaluatedConfig.path); | ||
|
@@ -2041,9 +2038,7 @@ class WebpackCLI { | |
|
||
async createCompiler(options, callback) { | ||
this.applyNodeEnv(options); | ||
|
||
let config = await this.resolveConfig(options); | ||
|
||
config = await this.applyOptions(config, options); | ||
config = await this.applyCLIPlugin(config, options); | ||
|
||
|
@@ -2077,7 +2072,7 @@ class WebpackCLI { | |
if (compiler && compiler.compiler) { | ||
compiler = compiler.compiler; | ||
} | ||
|
||
compiler.config = config; | ||
return compiler; | ||
} | ||
|
||
|
@@ -2171,7 +2166,15 @@ class WebpackCLI { | |
} | ||
|
||
compiler = await this.createCompiler(options, callback); | ||
|
||
if (options.watch) { | ||
// eslint-disable-next-line | ||
for (const [_, filePath] of compiler.config.path.entries()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do the same using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cant iterate over a weakmap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have configuration keys |
||
// eslint-disable-next-line | ||
fs.watchFile(filePath, async () => { | ||
compiler = await this.createCompiler(options, callback); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should rerun |
||
}); | ||
} | ||
} | ||
if (!compiler) { | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe and very bad for perf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its cache for one file, perf wont change that much because of this