Skip to content

Commit ab5b5d3

Browse files
committedJan 8, 2018
expose the resolve option
1 parent 1eb95a8 commit ab5b5d3

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed
 

‎README.md

+14
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,20 @@ Provides additional hash uniqueness. Might be useful for projects with several s
264264

265265
Short alias for the [postcss-modules-local-by-default](https://github.com/css-modules/postcss-modules-local-by-default) plugin's option.
266266

267+
268+
### `resolve` object
269+
270+
Changes the way the paths of ICSS imports will be resolved (`@value a from './b.css'` and `composes a from './b.css'`). Supports:
271+
272+
- `resolve.alias` `object`
273+
- `resolve.extensions` `array` — default value is `['.css']`.
274+
- `resolve.modules` `array`
275+
- `resolve.mainFile` `array` — default value is `'index.css'`.
276+
- `resolve.preserveSymlinks` `boolean` — default value is `false`.
277+
278+
See the detailed description at: https://github.com/css-modules/postcss-modules-resolve-imports#options
279+
280+
267281
### `rootDir` string
268282

269283
Provides absolute path to the project directory. Providing this will result in better generated class names. It can be obligatory, if you run require hook and build tools (like [css-modulesify](https://github.com/css-modules/css-modulesify)) from different working directories.

‎src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = function setupHook({
3434
generateScopedName,
3535
hashPrefix,
3636
mode,
37+
resolve: resolveOpts,
3738
use,
3839
rootDir: context = process.cwd(),
3940
}) {
@@ -67,7 +68,7 @@ module.exports = function setupHook({
6768
? new ExtractImports({createImportedName})
6869
: ExtractImports,
6970
new Scope({generateScopedName: scopedName}),
70-
new ResolveImports({resolve: {extensions: exts}}),
71+
new ResolveImports({resolve: Object.assign({}, {extensions: exts}, resolveOpts)}),
7172
...append,
7273
];
7374

‎src/validate.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const rules = {
2929
generateScopedName: 'function|string',
3030
hashPrefix: 'string',
3131
mode: 'string',
32+
resolve: 'object',
3233
rootDir: 'string',
3334
};
3435

‎test/api/fixture/shortcuts.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.color
2+
{
3+
composes: color from 'oceanic';
4+
}

‎test/api/resolve.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const {detachHook, dropCache} = require('../sugar');
2+
const path = require('path');
3+
4+
suite('api/resolve', () => {
5+
test('should be called', () => {
6+
const tokens = require('./fixture/shortcuts.css');
7+
8+
assert.deepEqual(tokens, {
9+
color: '_test_api_fixture_shortcuts__color _test_api_fixture_oceanic__color',
10+
});
11+
});
12+
13+
setup(() => {
14+
hook({resolve: {
15+
modules: [path.join(__dirname, 'fixture')],
16+
}});
17+
});
18+
19+
teardown(() => {
20+
detachHook('.css');
21+
dropCache('./api/fixture/oceanic.css');
22+
});
23+
});

0 commit comments

Comments
 (0)
Please sign in to comment.