Skip to content
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

webpack config appears to be re-executed once for every resolve attempt #96

Open
mogelbrod opened this issue Apr 27, 2021 · 2 comments
Open

Comments

@mogelbrod
Copy link

This greatly increases execution times for non-trivial webpack.config.js files. It would be great if the config would only be required and instantiated once, using memoization if necessary.

function resolveWebpackPath({dependency, filename, directory, webpackConfig}) {
if (!webpackResolve) {
webpackResolve = require('enhanced-resolve');
}
webpackConfig = path.resolve(webpackConfig);
let loadedConfig;
try {
loadedConfig = require(webpackConfig);
if (typeof loadedConfig === 'function') {
loadedConfig = loadedConfig();
}
} catch (e) {
debug('error loading the webpack config at ' + webpackConfig);
debug(e.message);
debug(e.stack);
return '';
}
const resolveConfig = Object.assign({}, loadedConfig.resolve);
if (!resolveConfig.modules && (resolveConfig.root || resolveConfig.modulesDirectories)) {
resolveConfig.modules = [];
if (resolveConfig.root) {
resolveConfig.modules = resolveConfig.modules.concat(resolveConfig.root);
}
if (resolveConfig.modulesDirectories) {
resolveConfig.modules = resolveConfig.modules.concat(resolveConfig.modulesDirectories);
}
}
try {
const resolver = webpackResolve.create.sync(resolveConfig);
// We don't care about what the loader resolves the dependency to
// we only wnat the path of the resolved file
dependency = stripLoader(dependency);
const lookupPath = isRelative(dependency) ? path.dirname(filename) : directory;
return resolver(lookupPath, dependency);
} catch (e) {
debug('error when resolving ' + dependency);
debug(e.message);
debug(e.stack);
return '';
}
}

@mrjoelkemp
Copy link
Collaborator

Hey @mogelbrod. Thanks for raising this. You're right!

Looks like TS has that type of preloaded config support. Webpack would follow a similar path.

Happy to review a PR with tests if you're open to it. Otherwise we can wait and see if anyone else has this issue and is willing to contribute a PR.

@mogelbrod
Copy link
Author

Hi again! Sorry for the late response.
I haven't used the library since May and so haven't really had a reason to fix this myself - so it's up for grabs if anybody else wants to try 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants