Skip to content

Commit 6050781

Browse files
smuemdjescalan
authored andcommitted
Expose post-css import path option (#14)
1 parent 346b559 commit 6050781

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ postcss: (ctx) => {
6262
| Name | Description | Default |
6363
| ---- | ----------- | ------- |
6464
| **root** | Root path used to resolve layouts and includes | |
65-
| **addDependencyTo** | Object with `addDependency` method that will get file paths for tracked deps from includes/layouts | |
65+
| **path** | A path to a folder or an array of paths, telling postcss-import where to look for sss or css files to `@import`. | Defaults to the `assets/css` folder. |
6666
| **webpack** | Shortcut for webpack users to set the `root` and `addDependencyTo` options more easily. Pass webpack loader context. | |
6767
| **browsers** | Browser support provided to [autoprefixer](http://cssnext.io/usage/#browsers) | `> 1%, last 2 versions, Firefox ESR` |
6868
| **features** | Enable or disable [cssnext features](http://cssnext.io/usage/#features) | |

lib/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ module.exports = (options = {}) => {
77
// sugarss by default unless false or custom parser
88
let parser = options.parser || sugarss
99
if (options.parser === false) parser = undefined
10+
options.path = options.path ? Array.prototype.concat(options.path) : []
1011

1112
// define addDependencyTo if the webpack object is provided
1213
if (options.webpack) {
13-
options.root = options.webpack.resourcePath
14-
options.addDependencyTo = options.webpack
14+
options.root = options.webpack.options.context
15+
options.path.push(options.webpack.resourcePath)
1516
}
1617

1718
// standard options merge
18-
const importOpt = selectiveMerge(options, ['root', 'addDependencyTo'])
19+
const importOpt = selectiveMerge(options, ['root', 'addDependencyTo', 'path'])
1920
const cssnextOpt = selectiveMerge(options, ['browsers', 'features', 'warnForDuplicates'])
2021

2122
// define normal plugin list

test/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const test = require('ava')
66
test('basic', (t) => {
77
cssStandardsRewired.__set__('postcssImport', (opts) => {
88
t.truthy(opts.root === 'test')
9-
t.truthy(opts.addDependencyTo.addDependency === 'test')
9+
t.truthy(opts.path[0] === 'test/test1')
10+
t.truthy(opts.path[1] === 'test/test2')
11+
t.truthy(opts.path[2] === 'test') // webpack.resourcePath
1012
})
1113

1214
cssStandardsRewired.__set__('cssnext', (opts) => {
@@ -21,7 +23,12 @@ test('basic', (t) => {
2123

2224
const out1 = cssStandardsRewired({
2325
parser: false,
24-
webpack: { resourcePath: 'test', addDependency: 'test' },
26+
webpack: {
27+
resourcePath: 'test',
28+
addDependency: 'test',
29+
options: { context: 'test' }
30+
},
31+
path: ['test/test1', 'test/test2'],
2532
features: 'test',
2633
browsers: 'test',
2734
warnForDuplicates: 'test',

0 commit comments

Comments
 (0)