-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
A loader with exclude function can not merge ideally #75
Comments
Please see merge.smartStrategy. You can override the default behavior there for more control. Going with override in this particular case would break basic assumptions I think. |
Firstly, i have to apologize for what i said above, here, i will show this issue correctly: const loader1= { module:{ rules:[{ test: /\.jsx$/, exclude: function(path){ var isNpmModule=!!path.match(/node_modules/); return isNpmModule; }, use:[{ loader: 'babel-loader', options:{ } }] }] } } const loader2 = { module:{ rules:[ { test: /\.jsx$/, exclude: function(path){ var isNpmModule=!!path.match(/node_modules/); return isNpmModule; }, use:[{ loader: 'after', options:{} }] }] } } const defaultWebpackConfig = merge(loader1,loader2); const webpackRules = merge.smart({ rules: loader1.module.rules }, { rules:loader2.module.rules }); defaultWebpackConfig.module.rules = webpackRules.rules; Actually, i want to combine two rules into one while actually i still get an object as bellow: [ { test: { /\.jsx$/ [lastIndex]: 0 }, exclude: { [Function: exclude] [length]: 1, [name]: 'exclude', [arguments]: null, [caller]: null, [prototype]: exclude { [constructor]: [Circular] } }, use: [ { loader: 'babel-loader', options: {} }, [length]: 1 ] }, { test: { /\.jsx$/ [lastIndex]: 0 }, exclude: { [Function: exclude] [length]: 1, [name]: 'exclude', [arguments]: null, [caller]: null, [prototype]: exclude { [constructor]: [Circular] } }, use: [ { loader: 'after', options: {} }, [length]: 1 ] }, [length]: 2 ] You can see above that there are two rule test. But, if you replace function with a string, for example: exclude:'node_modules' You will get what you want(Only one test rule leaved): [ { test: { /\.jsx$/ [lastIndex]: 0 }, exclude: 'node_modules', use: [ { loader: 'babel-loader', options: {} }, { loader: 'after', options: {} }, [length]: 2 ] }, [length]: 1 ] |
Ah, yeah. I think the problem is that the current code doesn't have any specific support for functions yet. It would probably have to run possible functions to see how they evaluate to see if they give the same result so the rules can be merged. The problem is that webpack controls Maybe the best option would be to document this as there's no way to "fix" it in webpack-merge. |
It is interesting that function merging has been implemented in v0.20.0. And I tested locally, v4.2.2, only got one rule test.
|
I'll drop support for |
Bellow is an example i encountered of webpack2, i hope someone can give me some suggestions:
Actually, i want second loader will override previous one, but actually i get one as bellow:
The text was updated successfully, but these errors were encountered: