Skip to content

Commit

Permalink
Add addModulesDirectories config (#256)
Browse files Browse the repository at this point in the history
* Add `addModulesDirectories` config

Allows appending to the default list of modules directories.

Relevant discussion:

#195
  • Loading branch information
neezer authored and RyanZim committed Dec 16, 2016
1 parent 32470ed commit 028663b
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -198,6 +198,19 @@ postcss: function(webpack) {
}
```

#### `addModulesDirectories`

Type: `Array`
Default: `[]`

An array of folder names to add to [Node's resolver](https://github.com/substack/node-resolve).
Values will be appended to the default resolve directories:
`["node_modules", "web_modules"]`.

This option is only for adding additional directories to default resolver. If
you provide your own resolver via the `resolve` configuration option above, then
this value will be ignored.

#### Example with some options

```js
Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -16,6 +16,7 @@ function AtImport(options) {
resolve: resolveId,
load: loadContent,
plugins: [],
addModulesDirectories: [],
}, options)

options.root = path.resolve(options.root)
Expand Down
2 changes: 1 addition & 1 deletion lib/resolve-id.js
Expand Up @@ -29,7 +29,7 @@ module.exports = function(id, base, options) {

var resolveOpts = {
basedir: base,
moduleDirectory: moduleDirectories,
moduleDirectory: moduleDirectories.concat(options.addModulesDirectories),
paths: paths,
extensions: [ ".css" ],
packageFilter: function processPackage(pkg) {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/resolve-custom-modules.css
@@ -0,0 +1,7 @@
@import "shared-fake";
@import "shared-auto";
@import "shared-nest";
@import "shared-by-hand/style.css";
@import "shared-use-dep";
@import "shared-use-dep-too";
@import "shared-use-dep" screen;
8 changes: 8 additions & 0 deletions test/fixtures/resolve-custom-modules.expected.css
@@ -0,0 +1,8 @@
.shared-fake{}
.shared-auto{}
.shared-nested{}
.shared-byHand{}
.shared-dep{}
@media screen{
.shared-dep{}
}
9 changes: 9 additions & 0 deletions test/resolve.js
Expand Up @@ -54,3 +54,12 @@ test("should be able to consume npm package or local modules", t => {
from: "fixtures/imports/foo.css",
})
})

test("should be able to consume modules from custom modules directories", t => {
return compareFixtures(t, "resolve-custom-modules", {
path: null,
addModulesDirectories: [ "shared_modules" ],
}, {
from: "fixtures/imports/foo.css",
})
})
1 change: 1 addition & 0 deletions test/shared_modules/shared-auto/index.css
@@ -0,0 +1 @@
.shared-auto{}
1 change: 1 addition & 0 deletions test/shared_modules/shared-by-hand/style.css
@@ -0,0 +1 @@
.shared-byHand{}
1 change: 1 addition & 0 deletions test/shared_modules/shared-dep/index.css
@@ -0,0 +1 @@
.shared-dep{}
1 change: 1 addition & 0 deletions test/shared_modules/shared-fake/main.css
@@ -0,0 +1 @@
.shared-fake{}
3 changes: 3 additions & 0 deletions test/shared_modules/shared-fake/package.json
@@ -0,0 +1,3 @@
{
"style": "main.css"
}
1 change: 1 addition & 0 deletions test/shared_modules/shared-nest/index.css
@@ -0,0 +1 @@
@import "shared-ed";
@@ -0,0 +1 @@
.shared-nested{}
1 change: 1 addition & 0 deletions test/shared_modules/shared-use-dep-too/index.css
@@ -0,0 +1 @@
@import "shared-dep";
1 change: 1 addition & 0 deletions test/shared_modules/shared-use-dep/index.css
@@ -0,0 +1 @@
@import "shared-dep";

0 comments on commit 028663b

Please sign in to comment.