// A webpack loader that returns invalid CSS with a source map.
// The source map points back to the original file, making it clear that the
// loader is responsible for the broken output (not the original source).
module.exports = function (source) {
// Generate a source map that maps generated lines back to the original source.
// The original file is valid CSS; the generated output is intentionally broken.
//
// Mapping (0-based line numbers):
// generated line 0 ("/* Generated by... */") -> original line 0 (".page {")
// generated line 1 (".page {") -> original line 0 (".page {")
// generated line 2 (" color: red") -> original line 1 (" color: blue;")
// generated line 3 (" @@@ ...") -> original line 2 (" font-size: 16px;")
// generated line 4 (" background: {{{...") -> original line 1 (" color: blue;")
// generated line 5 ("}") -> original line 3 ("}")
const sourceMap = {
version: 3,
sources: [this.resourcePath],
sourcesContent: [source],
mappings: 'AAAA;AAAA;AACE;AACA;AADA;AAEF',
names: [],
}
// Return broken CSS that will fail to parse
const brokenCss = `/* Generated by broken-css-loader */
.page {
color: red
@@@ THIS IS NOT VALID CSS @@@;
background: {{{ invalid
}
`
this.callback(null, brokenCss, sourceMap)
}