保誠-保戶業務員媒合平台
Tomas
2022-05-19 957a1f10a06fdbb76f1a0ba94fe44126c613fee3
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
import fs from 'fs';
import util from 'util';
 
import type {LoaderContext, StyleResource, StyleResourcesLoaderNormalizedOptions} from '..';
 
import {matchFiles} from './match-files';
import {resolveImportUrl} from './resolve-import-url';
 
export const getResources = async (ctx: LoaderContext, options: StyleResourcesLoaderNormalizedOptions) => {
    const {resolveUrl} = options;
 
    const files = await matchFiles(ctx, options);
 
    files.forEach(file => ctx.dependency(file));
 
    const resources = await Promise.all(
        files.map(async file => {
            const content = await util.promisify(fs.readFile)(file, 'utf8');
            const resource: StyleResource = {file, content};
 
            return resolveUrl ? resolveImportUrl(ctx, resource) : resource;
        }),
    );
 
    return resources;
};