fix(webpack): fix fragment css not being applied with webpack (#5172)

Support css files for fragments to be registered using global.registerModule
and global.registerWebpackModules.
This commit is contained in:
Martin Yankov
2017-12-14 18:51:44 +02:00
committed by Vasil Chimev
parent 0986315374
commit 60773e7545
2 changed files with 39 additions and 14 deletions

View File

@@ -115,15 +115,28 @@ function loadCustomComponent(componentPath: string, componentName?: string, attr
result = getComponentModule(componentName, componentPath, attributes, context);
}
// Add component CSS file if exists.
var cssFilePath = resolveFileName(fullComponentPathFilePathWithoutExt, "css");
if (cssFilePath) {
if (parentPage && typeof (<any>parentPage).addCssFile === "function") {
(<any>parentPage).addCssFile(cssFilePath);
} else {
ensureTrace();
// webpack modules require paths to be relative to /app folder.
let cssModulePath = fullComponentPathFilePathWithoutExt + ".css";
if (cssModulePath.startsWith("/")) {
var app = knownFolders.currentApp().path + "/";
if (cssModulePath.startsWith(app)) {
cssModulePath = "./" + cssModulePath.substr(app.length);
}
}
trace.write("CSS file found but no page specified. Please specify page in the options!", trace.categories.Error, trace.messageType.error);
// Add CSS from webpack module if exists.
if (global.moduleExists(cssModulePath)) {
(<any>parentPage).addCssFile(cssModulePath);
} else {
var cssFilePath = resolveFileName(fullComponentPathFilePathWithoutExt, "css");
// Add component CSS file if exists.
if (cssFilePath) {
if (parentPage && typeof (<any>parentPage).addCssFile === "function") {
(<any>parentPage).addCssFile(cssFilePath);
} else {
ensureTrace();
trace.write("CSS file found but no page specified. Please specify page in the options!", trace.categories.Error, trace.messageType.error);
}
}
}