-
Notifications
You must be signed in to change notification settings - Fork 94
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
resolve.extensions cannot be configured properly #176
Comments
From what I read, the vanilla way is now the default. I think it's good to have the defaults set, as this is what probably >90% (number out of the blue) of users are doing. You can set the What I would find useful is replacing the Another option would be an {
prepend: true,
replace: false,
append: false // default
} Or directly a string from enum Examplesextensions(['.custom.js'], 'prepend')
extensions(['.custom.js'], { replace: true }) @andywer what do you think? |
Can be done by using const webpackMerge = require('webpack-merge')
const baseConfig = {
resolve: {
// Explicitly define default extensions, otherwise blocks will overwrite them instead of extending
extensions: ['.js', '.json']
},
module: {
rules: []
},
plugins: []
}
const configSnippet = {
resolve: {
extensions: ['.custom.js', '.js']
}
}
const result = webpackMerge.smartStrategy({ 'resolve.extensions': 'replace' })(baseConfig, configSnippet)
// output
{
resolve: {
extensions: [ '.custom.js', '.js' ]
},
module: { rules: [] },
plugins: []
} |
@zcei @TombolaShepless Thanks for your feedback and for creating the issue! How about we change the behavior of |
@zcei @andywer both of those solutions sound fine to me. If pushed, I'd probably swing towards the prepend approach for a reason @zcei mentioned above:
If you need anything but standard extensions you (should) know what you want/are doing. Therefore, rather than adding complexity on top of what is a very simple configuration block, it would make more sense to just prepend the custom values. UPDATE const config = {
resolve: {
extensions: ['.js', '.json']
}
}
const customExtensions = ['.mobile.js', '.js'];
config.resolve.extensions = [...customExtensions, ...config.resolve.extensions];
console.log(config.resolve.extensions);
// ['.mobile.js', '.js', '.js', '.json'] I guess we could do some clean up to remove dupes? |
The dupes shouldn't be of much impact here as it would match the first index and then stops looking further - I guess 😆 If I'm not mistaken, we would only need to change this line: // before:
function merge (configSnippet) {
return prevConfig => webpackMerge.smart(prevConfig, configSnippet)
}
// after
const webpackBlocksMerge = webpackMerge.smartStrategy({ 'resolve.extensions': 'prepend' })
function merge (configSnippet) {
return prevConfig => webpackBlocksMerge(prevConfig, configSnippet)
} I like your vanilla solution and usually this would be the go-to way for me, but |
Looks fine to me. @sapegin @jvanbruegge Objections? |
Looks good to me too ;-) |
Fixed by #177 |
From @TombolaShepless in #153:
The text was updated successfully, but these errors were encountered: