Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Add rule.resolve #265

Merged
merged 4 commits into from
Jul 1, 2020
Merged

Add rule.resolve #265

merged 4 commits into from
Jul 1, 2020

Conversation

cyjake
Copy link
Contributor

@cyjake cyjake commented Jun 2, 2020

Configuring resolve at rule level is possible starting from webpack 4.36.1, which is quite useful if same alias name (such as @) were shared at different level of packages.

@cyjake
Copy link
Contributor Author

cyjake commented Jun 7, 2020

ping @edmorley

@opl-
Copy link
Contributor

opl- commented Jun 7, 2020

Missing documentation in the README and types. Other than that LGTM.

Add types and documentation for Rule.resolve
@cyjake
Copy link
Contributor Author

cyjake commented Jun 10, 2020

ping @edmorley @opl- Is this pr ready to merge? Plz let me know if there still are any changes needed

@opl-
Copy link
Contributor

opl- commented Jun 16, 2020

Personally I'd say it's fine, but I have no power here. Up to @edmorley to review and merge.

@edmorley
Copy link
Member

@cyjake Hi! Thank you very much for opening this PR.

My day to day work no longer involves front-end development, so I don't actually use webpack any more, other than via helping to maintain Neutrino and webpack-chain - as such contributing to these projects is best effort. I can entirely emphasise with opening a PR and having to wait for it to be reviewed/merged - my oldest still-open public PR is from 3 years ago.

However I would like to politely suggest that pinging a PR 5 times in 21 days is too much, and in many cases might actually be counter-productive, since it might annoy maintainers, and mean they are less inclined to use their spare time to take a look. A gentler pinging schedule might be say T+2weeks, T+6weeks, T+3 months etc.

Anyway, I'll take a look at this PR at some point today.

Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think resolve also needs to be added here:

webpack-chain/src/Rule.js

Lines 122 to 127 in dd229b5

'include',
'exclude',
'use',
'rules',
'oneOf',
'test',

Similar to how resolve is handled in the existing Config.resolve usage:

webpack-chain/src/Config.js

Lines 144 to 148 in dd229b5

merge(obj = {}, omit = []) {
const omissions = [
'node',
'output',
'resolve',

Could you also add some merge tests to catch this missing change in merge()? eg Add to the objects here:

webpack-chain/test/Rule.js

Lines 180 to 402 in 6bb22fc

test('merge empty', () => {
const rule = new Rule();
const obj = {
enforce: 'pre',
test: /\.js$/,
include: ['alpha', 'beta'],
exclude: ['alpha', 'beta'],
rules: {
minifier: {
resourceQuery: /minify/,
use: {
minifier: {
loader: 'minifier-loader',
},
},
},
},
oneOf: {
inline: {
resourceQuery: /inline/,
use: {
url: {
loader: 'url-loader',
},
},
},
},
use: {
babel: {
loader: 'babel-loader',
options: {
presets: ['alpha'],
},
},
},
};
const instance = rule.merge(obj);
expect(instance).toBe(rule);
expect(rule.toConfig()).toStrictEqual({
enforce: 'pre',
test: /\.js$/,
include: ['alpha', 'beta'],
exclude: ['alpha', 'beta'],
rules: [
{
resourceQuery: /minify/,
use: [
{
loader: 'minifier-loader',
},
],
},
],
oneOf: [
{
resourceQuery: /inline/,
use: [
{
loader: 'url-loader',
},
],
},
],
use: [
{
loader: 'babel-loader',
options: {
presets: ['alpha'],
},
},
],
});
});
test('merge with values', () => {
const rule = new Rule();
rule
.test(/\.js$/)
.post()
.include.add('gamma')
.add('delta')
.end()
.use('babel')
.loader('babel-loader')
.options({ presets: ['alpha'] });
rule.merge({
test: /\.jsx$/,
enforce: 'pre',
include: ['alpha', 'beta'],
exclude: ['alpha', 'beta'],
rules: {
minifier: {
resourceQuery: /minify/,
use: {
minifier: {
loader: 'minifier-loader',
},
},
},
},
oneOf: {
inline: {
resourceQuery: /inline/,
use: {
url: {
loader: 'url-loader',
},
},
},
},
use: {
babel: {
options: {
presets: ['beta'],
},
},
},
});
expect(rule.toConfig()).toStrictEqual({
test: /\.jsx$/,
enforce: 'pre',
include: ['gamma', 'delta', 'alpha', 'beta'],
exclude: ['alpha', 'beta'],
rules: [
{
resourceQuery: /minify/,
use: [
{
loader: 'minifier-loader',
},
],
},
],
oneOf: [
{
resourceQuery: /inline/,
use: [
{
loader: 'url-loader',
},
],
},
],
use: [
{
loader: 'babel-loader',
options: {
presets: ['alpha', 'beta'],
},
},
],
});
});
test('merge with omit', () => {
const rule = new Rule();
rule
.test(/\.js$/)
.post()
.include.add('gamma')
.add('delta')
.end()
.use('babel')
.loader('babel-loader')
.options({ presets: ['alpha'] });
rule.merge(
{
test: /\.jsx$/,
enforce: 'pre',
include: ['alpha', 'beta'],
exclude: ['alpha', 'beta'],
rules: {
minifier: {
resourceQuery: /minify/,
use: {
minifier: {
loader: 'minifier-loader',
},
},
},
},
oneOf: {
inline: {
resourceQuery: /inline/,
use: {
url: {
loader: 'url-loader',
},
},
},
},
use: {
babel: {
options: {
presets: ['beta'],
},
},
},
},
['use', 'oneOf', 'rules'],
);
expect(rule.toConfig()).toStrictEqual({
test: /\.jsx$/,
enforce: 'pre',
include: ['gamma', 'delta', 'alpha', 'beta'],
exclude: ['alpha', 'beta'],
use: [
{
loader: 'babel-loader',
options: {
presets: ['alpha'],
},
},
],
});
});

test/Rule.js Show resolved Hide resolved
@cyjake cyjake force-pushed the rule-resolve-alias branch from 7287fdb to 2858caf Compare June 30, 2020 22:26
@cyjake cyjake requested a review from edmorley July 1, 2020 01:52
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - thank you :-)

@edmorley edmorley merged commit 4898e9c into neutrinojs:master Jul 1, 2020
@edmorley
Copy link
Member

edmorley commented Jul 1, 2020

Released in v6.5.0 :-)

@cyjake cyjake deleted the rule-resolve-alias branch July 2, 2020 02:29
@cyjake cyjake restored the rule-resolve-alias branch July 2, 2020 02:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

3 participants