mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
feat: apply-css-loader hmr code
This commit is contained in:
@ -186,7 +186,9 @@ export default function (config: Config, env: IWebpackEnv): Config {
|
||||
/* for compat only */ 'global.isAndroid': platform === 'android',
|
||||
/* for compat only */ 'global.isIOS': platform === 'ios',
|
||||
process: 'global.process',
|
||||
/* todo: remove if fixed in core? */ profile: '() => {}',
|
||||
|
||||
// todo: ?!?!
|
||||
// profile: '() => {}',
|
||||
},
|
||||
]);
|
||||
|
||||
|
@ -12,14 +12,28 @@ export default function loader(content, map) {
|
||||
.some(({ path }) => path.includes(loader));
|
||||
};
|
||||
// add a tag to the applied css
|
||||
const tag =
|
||||
const tag = JSON.stringify(this.resourcePath);
|
||||
const tagCode =
|
||||
this.mode === 'development' ? `, ${JSON.stringify(this.resourcePath)}` : '';
|
||||
|
||||
const hmrCode = this.hot
|
||||
? dedent`
|
||||
if(module.hot) {
|
||||
module.hot.accept()
|
||||
module.hot.dispose(() => {
|
||||
const { removeTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
removeTaggedAdditionalCSS(${tag})
|
||||
})
|
||||
}
|
||||
`
|
||||
: ``;
|
||||
|
||||
if (hasLoader('apply-css-loader')) {
|
||||
content = dedent`
|
||||
${content}
|
||||
const { addTaggedAdditionalCSS } = require("@nativescript/core/ui/styling/style-scope");
|
||||
addTaggedAdditionalCSS(___CSS2JSON_LOADER_EXPORT___${tag})
|
||||
addTaggedAdditionalCSS(___CSS2JSON_LOADER_EXPORT___${tagCode})
|
||||
${hmrCode}
|
||||
`;
|
||||
} else if (hasLoader('css-loader')) {
|
||||
content = dedent`
|
||||
@ -29,10 +43,11 @@ export default function loader(content, map) {
|
||||
___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});
|
||||
addTaggedAdditionalCSS(cssExport[1]${tagCode});
|
||||
}
|
||||
});
|
||||
}
|
||||
${hmrCode}
|
||||
`;
|
||||
} else {
|
||||
this.emitWarning(new Error(cssLoaderWarning));
|
||||
|
Reference in New Issue
Block a user