Skip to content

Commit 4f13070

Browse files
authored
Merge pull request #825 from hypothesis/duplicated-sourcemap
Do not duplicate sourcemap URLs when building non-sass styles
2 parents 7eb43f4 + 43719a5 commit 4f13070

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/css.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ export async function buildCSS(inputs, { tailwind = false } = {}) {
7070
prev: sourceMap ? JSON.stringify(sourceMap) : undefined,
7171
},
7272
});
73-
const sourceMappingURL = relative(dirname(output), sourceMapPath);
7473

75-
await writeFile(
76-
output,
77-
// We have to manually add the sourceMappingURL comment, because
78-
// `sass.compile(...)` does not do it by itself.
79-
// https://sass-lang.com/documentation/js-api/interfaces/Options#sourceMap
80-
// It's important to know that URI-encoding the sourceMappingURL might
81-
// be needed if we start using characters outside the [0-9a-zA-Z-_.] set
82-
// in file names
83-
`${postcssResult.css}\n/*# sourceMappingURL=${sourceMappingURL} */`,
84-
);
74+
const sourceMappingURL =
75+
sourceMap && relative(dirname(output), sourceMapPath);
76+
77+
// We have to manually add the sourceMappingURL comment, because
78+
// `sass.compile(...)` does not do it by itself.
79+
// https://sass-lang.com/documentation/js-api/interfaces/Options#sourceMap
80+
// It's important to know that URI-encoding the sourceMappingURL might
81+
// be needed if we start using characters outside the [0-9a-zA-Z-_.] set
82+
// in file names
83+
const content = sourceMappingURL
84+
? `${postcssResult.css}\n/*# sourceMappingURL=${sourceMappingURL} */`
85+
: postcssResult.css;
86+
87+
await writeFile(output, content);
8588
await writeFile(sourceMapPath, postcssResult.map.toString());
8689
}),
8790
);

0 commit comments

Comments
 (0)