MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / loader

Function loader

packages/webpack5/src/loaders/css2json-loader/index.ts:9–41  ·  view source on GitHub ↗
(content: string, map: any)

Source from the content-addressed store, hash-verified

7const inlineLoader = '!css2json-loader?useForImports!';
8
9export default function loader(content: string, map: any) {
10 const options = this.getOptions() || {};
11 const inline = !!options.useForImports;
12 const requirePrefix = inline ? inlineLoader : '';
13
14 const ast = parse(content);
15
16 // todo: revise if this is necessary
17 // todo: perhaps use postCSS and just build imports into a single file?
18 let dependencies = [];
19 getAndRemoveImportRules(ast)
20 .map(extractUrlFromRule)
21 .map(createRequireUri)
22 .forEach(({ uri, requireURI }) => {
23 dependencies.push(`require("${requirePrefix}${requireURI}")`);
24 });
25
26 const str = JSON.stringify(ast, (k, v) => (k === 'position' ? undefined : v));
27
28 // map.mappings = map.mappings.replace(/;{2,}/, '')
29
30 const code = dedent`
31 /* CSS2JSON */
32 ${dependencies.join('\n')}
33 const ___CSS2JSON_LOADER_EXPORT___ = ${str}
34 export default ___CSS2JSON_LOADER_EXPORT___
35 `;
36 this.callback(
37 null,
38 code, //`${dependencies.join('\n')}module.exports = ${str};`,
39 map
40 );
41}
42
43function getImportRules(ast: Stylesheet): Import[] {
44 if (!ast || (<any>ast).type !== 'stylesheet' || !ast.stylesheet) {

Callers

nothing calls this directly

Calls 7

parseFunction · 0.90
getAndRemoveImportRulesFunction · 0.85
forEachMethod · 0.80
joinMethod · 0.80
callbackMethod · 0.80
mapMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected