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

Use the Resolve API to define ResolveLoader according to webpack #99

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,31 +529,8 @@ config.resolve.mainFiles

#### Config resolveLoader

```js
config.resolveLoader : ChainedMap
```

#### Config resolveLoader extensions

```js
config.resolveLoader.extensions : ChainedSet

config.resolveLoader.extensions
.add(value)
.prepend(value)
.clear()
```

#### Config resolveLoader modules

```js
config.resolveLoader.modules : ChainedSet

config.resolveLoader.modules
.add(value)
.prepend(value)
.clear()
```
The API for `config.resolveLoader` is identical to `config.resolve` with
the following additions:

#### Config resolveLoader moduleExtensions

Expand Down Expand Up @@ -1088,10 +1065,26 @@ config.merge({
resolveLoader: {
[key]: value,

alias: {
[key]: value
},
aliasFields: [...values],
descriptionFields: [...values],
extensions: [...values],
mainFields: [...values],
mainFiles: [...values],
modules: [...values],
moduleExtensions: [...values],
packageMains: [...values]
packageMains: [...values],

plugin: {
[name]: {
plugin: WebpackPlugin,
args: [...args],
before,
after
}
}
},

module: {
Expand Down
17 changes: 4 additions & 13 deletions src/ResolveLoader.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const ChainedMap = require('./ChainedMap');
const Resolve = require('./Resolve');
const ChainedSet = require('./ChainedSet');

module.exports = class extends ChainedMap {
module.exports = class extends Resolve {
constructor(parent) {
super(parent);
this.extensions = new ChainedSet(this);
this.modules = new ChainedSet(this);
this.moduleExtensions = new ChainedSet(this);
this.packageMains = new ChainedSet(this);
}
Expand All @@ -14,23 +12,16 @@ module.exports = class extends ChainedMap {
return this.clean(
Object.assign(
{
extensions: this.extensions.values(),
modules: this.modules.values(),
moduleExtensions: this.moduleExtensions.values(),
packageMains: this.packageMains.values(),
},
this.entries() || {}
super.toConfig()
)
);
}

merge(obj, omit = []) {
const omissions = [
'extensions',
'modules',
'moduleExtensions',
'packageMains',
];
const omissions = ['moduleExtensions', 'packageMains'];

omissions.forEach(key => {
if (!omit.includes(key) && key in obj) {
Expand Down