mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: external config loading
+refactor many pieces
This commit is contained in:
@@ -11,33 +11,29 @@ export default function loader(content, map) {
|
||||
?.slice(this.loaderIndex)
|
||||
.some(({ path }) => path.includes(loader));
|
||||
};
|
||||
// add a tag to the applied css
|
||||
const tag =
|
||||
this.mode === 'development' ? `, ${JSON.stringify(this.resourcePath)}` : '';
|
||||
|
||||
if (hasLoader('apply-css-loader')) {
|
||||
// add a tag to the applied css
|
||||
const tag =
|
||||
this.mode === 'development'
|
||||
? `, ${JSON.stringify(this.resourcePath)}`
|
||||
: '';
|
||||
content = dedent`
|
||||
${content}
|
||||
const { addTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
addTaggedAdditionalCSS(___CSS2JSON_LOADER_EXPORT___${tag})
|
||||
${content}
|
||||
const { addTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
addTaggedAdditionalCSS(___CSS2JSON_LOADER_EXPORT___${tag})
|
||||
`;
|
||||
} else if (hasLoader('css-loader')) {
|
||||
content = dedent`
|
||||
${content}
|
||||
// apply css
|
||||
const { Application } = require("@nativescript/core");
|
||||
require("@nativescript/core/ui/styling/style-scope");
|
||||
if (___CSS_LOADER_EXPORT___ && typeof ___CSS_LOADER_EXPORT___.forEach === "function") {
|
||||
___CSS_LOADER_EXPORT___.forEach(cssExport => {
|
||||
if (cssExport.length > 1 && cssExport[1]) {
|
||||
// applying the second item of the export as it contains the css contents
|
||||
Application.addCss(cssExport[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
`;
|
||||
${content}
|
||||
const { addTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
if (___CSS_LOADER_EXPORT___ && typeof ___CSS_LOADER_EXPORT___.forEach === "function") {
|
||||
___CSS_LOADER_EXPORT___.forEach(cssExport => {
|
||||
if (cssExport.length > 1 && cssExport[1]) {
|
||||
// applying the second item of the export as it contains the css contents
|
||||
addTaggedAdditionalCSS(cssExport[1]${tag});
|
||||
}
|
||||
});
|
||||
}
|
||||
`;
|
||||
} else {
|
||||
this.emitWarning(new Error(cssLoaderWarning));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ export default function loader(content: string, map: any) {
|
||||
|
||||
const ast = parse(content);
|
||||
|
||||
// todo: revise if this is necessary
|
||||
// todo: perhaps use postCSS and just build imports into a single file?
|
||||
let dependencies = [];
|
||||
getImportRules(ast)
|
||||
.map(extractUrlFromRule)
|
||||
@@ -37,9 +39,7 @@ export default function loader(content: string, map: any) {
|
||||
const code = dedent`
|
||||
/* CSS2JSON */
|
||||
${dependencies.join('\n')}
|
||||
|
||||
const ___CSS2JSON_LOADER_EXPORT___ = ${str}
|
||||
|
||||
export default ___CSS2JSON_LOADER_EXPORT___
|
||||
`;
|
||||
this.callback(
|
||||
|
||||
Reference in New Issue
Block a user