File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 1
1
// Polyfill for btoa in Node.js
2
2
/* global btoa */
3
- function getBtoa() {
4
- if (typeof btoa === "function") return btoa;
5
- return (str) => Buffer.from(str, "binary").toString("base64");
6
- }
7
3
8
4
module.exports = (item) => {
9
5
const [, content, , cssMapping] = item;
@@ -12,8 +8,15 @@ module.exports = (item) => {
12
8
return content;
13
9
}
14
10
15
- const btoaFn = getBtoa();
16
- const base64 = btoaFn(
11
+ const btoaPolyfill =
12
+ typeof btoa === "undefined"
13
+ ? (str) => {
14
+ const buffer =
15
+ str instanceof Buffer ? str : Buffer.from(str.toString(), "binary");
16
+ return buffer.toString("base64");
17
+ }
18
+ : btoa;
19
+ const base64 = btoaPolyfill(
17
20
unescape(encodeURIComponent(JSON.stringify(cssMapping))),
18
21
);
19
22
const data = `sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
You can’t perform that action at this time.
0 commit comments