1 |
|
2 |
|
3 | const tokenize = require('postcss/lib/tokenize');
|
4 |
|
5 | const urlPattern = /^url\((.+)\)/;
|
6 |
|
7 | module.exports = (node) => {
|
8 | const { name, params = '' } = node;
|
9 |
|
10 | if (name === 'import' && params.length) {
|
11 | node.import = true;
|
12 |
|
13 | const tokenizer = tokenize({ css: params });
|
14 |
|
15 | node.filename = params.replace(urlPattern, '$1');
|
16 |
|
17 | while (!tokenizer.endOfFile()) {
|
18 | const [type, content] = tokenizer.nextToken();
|
19 |
|
20 | if (type === 'word' && content === 'url') {
|
21 | return;
|
22 | } else if (type === 'brackets') {
|
23 | node.options = content;
|
24 | node.filename = params.replace(content, '').trim();
|
25 | break;
|
26 | }
|
27 | }
|
28 | }
|
29 | };
|