On Sitecore 10.1, we have a pretty standard SXA CLI setup.
in gulp\config.js
the following settings are set for Css handling.
css: {
path: ['styles/**/*.css','styles/**/*.css.map'],
targetPath: '',
minificationPath: ['styles/*.css'],
cssOptimiserFilePath: 'styles/',
cssOptimiserFileName: 'pre-optimized-min.css',
cssSourceMap: true,
enableMinification: true,
disableSourceUploading: true
},
So essentially I want (expect) SXA CLI to minify my CSS files, generate a Source Map for them, and upload the minified results (but not the CSS files themselves).
And it does appear that SXA CLI tries to do exactly that, but my pre-optimized-min.css.map
ends up not getting uploaded. Instead the CLI gives me:
Incorrect File Name.
Sending of file pre-optimized-min.css.map was skipped
I did some digging and I think the problem might be that there is a bug in the CLI code. The error message comes from this function:
module.exports = function(filePath) {
let excludedPath = config.excludedPath.some(function(element, index, array) {
return testPath(element, filePath)
});
let nameValidation = config.serverNameValidation.some(function(element, index, array) {
let pathNoExtension = path.basename(filePath).replace(/\.[^/.]+$/, ""),
nameValidation = !testPath(element, pathNoExtension);
if (nameValidation) {
console.log('Incorrect File Name.'.blue);
}
return nameValidation;
});
return !!(excludedPath || nameValidation);
}
And somehow this regex gets tripped up by the fact that the map file has a .css.map
extension. But I'm not sure - all I know is, that the error definitely comes from here.
So the question is; how can I work around this issue?
The SXA CLI, when doing sxa build Css
generates two files for me:
- pre-optimized-min.css
- pre-optimized-min.css.map
But it is only capable of uploading the pre-optimized-min.css
file. It fails on the other one - a file generated by its own build output.
How is this flow intended to work? or how can it be worked around without modifying files we do not own (like files inside node_modules\@SXA\celt
and so on).
Chrome clearly expects something. It throws up a warning like DevTools failed to load source map: Could not parse content for https://main.mysite.localho.st/-/media/Themes/Tenants/MyTetant/Main/Main/styles/pre-optimized-min.css.map: Unexpected token @ in JSON at position 0
. When investigating the request, SXA returns the original .css file in response to the .css.map request, causing this warning.