diff --git a/README.md b/README.md index e15ecd1..f92c18e 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,19 @@ dataPacker({ }) ``` +You can use functions as values of `dest.path` and `dest.path.map.annotation`. This functions must return strings. +Example (from #13): + +```js +dataPacker({ + dest: { + path: function (opts) { + return path.join('build/css', path.basename(opts.from, '.css') + '.data.css'); + } + } +}) +``` + ### Using diff --git a/README.ru.md b/README.ru.md index 14029e0..b2b232f 100644 --- a/README.ru.md +++ b/README.ru.md @@ -90,6 +90,19 @@ dataPacker({ }) ``` +Значениями параметров `dest.path` и `dest.path.map.annotation` также могут быть функции, которые должны возвращать строку. +Пример использования (из #13): + +```js +dataPacker({ + dest: { + path: function (opts) { + return path.join('build/css', path.basename(opts.from, '.css') + '.data.css'); + } + } +}) +``` + ### Подключение diff --git a/index.js b/index.js index d3988d9..379bd9a 100644 --- a/index.js +++ b/index.js @@ -179,7 +179,7 @@ function generateDataFile (css, opts) { var data = dataCSS.toResult({ to: (typeof opts.dest.path === 'function') ? opts.dest.path(opts) : opts.dest.path, - map: (typeof opts.dest.map === 'function') ? opts.dest.map(opts) : opts.dest.map + map: opts.dest.map }); if (!data.css.length) return; @@ -201,6 +201,7 @@ function extend (target, source) { Object.keys(source).map(function (prop) { prop in a && (a[prop] = source[prop]); }); + return a; }; @@ -241,7 +242,8 @@ function getMapPath (opts) { var result; if (opts.map.annotation) { - result = path.dirname(opts.to) +'/'+ opts.map.annotation; + result = (typeof opts.map.annotation === 'function') ? opts.map.annotation(opts) : opts.map.annotation; + result = path.join(path.dirname(opts.to), result); } else { result = opts.to +'.map'; diff --git a/package.json b/package.json index ebefba9..1f1b1d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-data-packer", - "version": "1.1.0", + "version": "1.2.0", "description": "PostCSS plugin to move an embedded data into a separate file", "keywords": [ "css",