Skip to content

Commit 028663b

Browse files
neezerRyanZim
authored andcommitted
Add addModulesDirectories config (#256)
* Add `addModulesDirectories` config Allows appending to the default list of modules directories. Relevant discussion: #195
1 parent 32470ed commit 028663b

File tree

15 files changed

+50
-1
lines changed

15 files changed

+50
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ postcss: function(webpack) {
198198
}
199199
```
200200

201+
#### `addModulesDirectories`
202+
203+
Type: `Array`
204+
Default: `[]`
205+
206+
An array of folder names to add to [Node's resolver](https://github.com/substack/node-resolve).
207+
Values will be appended to the default resolve directories:
208+
`["node_modules", "web_modules"]`.
209+
210+
This option is only for adding additional directories to default resolver. If
211+
you provide your own resolver via the `resolve` configuration option above, then
212+
this value will be ignored.
213+
201214
#### Example with some options
202215

203216
```js

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function AtImport(options) {
1616
resolve: resolveId,
1717
load: loadContent,
1818
plugins: [],
19+
addModulesDirectories: [],
1920
}, options)
2021

2122
options.root = path.resolve(options.root)

lib/resolve-id.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = function(id, base, options) {
2929

3030
var resolveOpts = {
3131
basedir: base,
32-
moduleDirectory: moduleDirectories,
32+
moduleDirectory: moduleDirectories.concat(options.addModulesDirectories),
3333
paths: paths,
3434
extensions: [ ".css" ],
3535
packageFilter: function processPackage(pkg) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import "shared-fake";
2+
@import "shared-auto";
3+
@import "shared-nest";
4+
@import "shared-by-hand/style.css";
5+
@import "shared-use-dep";
6+
@import "shared-use-dep-too";
7+
@import "shared-use-dep" screen;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.shared-fake{}
2+
.shared-auto{}
3+
.shared-nested{}
4+
.shared-byHand{}
5+
.shared-dep{}
6+
@media screen{
7+
.shared-dep{}
8+
}

test/resolve.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@ test("should be able to consume npm package or local modules", t => {
5454
from: "fixtures/imports/foo.css",
5555
})
5656
})
57+
58+
test("should be able to consume modules from custom modules directories", t => {
59+
return compareFixtures(t, "resolve-custom-modules", {
60+
path: null,
61+
addModulesDirectories: [ "shared_modules" ],
62+
}, {
63+
from: "fixtures/imports/foo.css",
64+
})
65+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.shared-auto{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.shared-byHand{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.shared-dep{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.shared-fake{}

0 commit comments

Comments
 (0)