-
Notifications
You must be signed in to change notification settings - Fork 7
/
postcss.config.js
61 lines (58 loc) · 2.01 KB
/
postcss.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const path = require('path');
const resolve = require('@csstools/sass-import-resolve');
module.exports = ({file, options, env}) => {
if (['.scss', '.sass'].includes(file.extname)) {
return {
plugins: {
'autoprefixer': {},
}
}
} else {
return {
parser: 'postcss-scss',
plugins: [
//require('postcss-import')({
// from: file.dirname,
//}),
require('postcss-advanced-variables')({
importResolve: (id, cwd) => {
// https://github.com/jonathantneal/postcss-advanced-variables/issues/74
// このバグのせいで importPaths が使い物にならないので、
// importResolve で頑張って import する
const dirs = [cwd, path.resolve(__dirname, 'node_modules/normalize.css/'), path.resolve(__dirname, 'node_modules/')]
const promises = dirs.map(dir => {
return resolve(id, {
cwd: dir,
readFile: true,
}).then(resolved => {
if (!resolved) {
throw new Error('File to import not found or unreadable');
}
return resolved;
});
});
return Promise.allSettled(promises).then(results => {
for (const r of results) {
if (r.status === 'fulfilled') {
return r.value;
}
}
throw new Error('File to import not found');
});
}
}),
require('autoprefixer')({}),
require('postcss-mixins')({}),
require('postcss-nesting')({}),
require('postcss-nested')({}),
require('cssnano')(options.env === 'production' ? Object.assign({}, options.cssnano || {}, {autoprefixer: false}) : false),
require('postcss-color-function')({}),
require('postcss-calc')({
warnWhenCannotResolve: true,
// mediaQueries: true,
// selectors: true,
}),
],
}
}
}