UNPKG

1.04 kBJavaScriptView Raw
1'use strict'
2
3const req = require('import-cwd')
4
5/**
6 * Load Options
7 *
8 * @private
9 * @method options
10 *
11 * @param {Object} config PostCSS Config
12 *
13 * @return {Object} options PostCSS Options
14 */
15const options = (config, file) => {
16 if (config.parser && typeof config.parser === 'string') {
17 try {
18 config.parser = req(config.parser)
19 } catch (err) {
20 throw new Error(`Loading PostCSS Parser failed: ${err.message}\n\n(@${file})`)
21 }
22 }
23
24 if (config.syntax && typeof config.syntax === 'string') {
25 try {
26 config.syntax = req(config.syntax)
27 } catch (err) {
28 throw new Error(`Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})`)
29 }
30 }
31
32 if (config.stringifier && typeof config.stringifier === 'string') {
33 try {
34 config.stringifier = req(config.stringifier)
35 } catch (err) {
36 throw new Error(`Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})`)
37 }
38 }
39
40 if (config.plugins) {
41 delete config.plugins
42 }
43
44 return config
45}
46
47module.exports = options