* Convert a CSS Source into a JS string literal, splicing `__webpack_require__.h()` for `[fullhash]` placeholders. * @param {Source} cssSource the CSS source * @param {import("../../declarations/WebpackOptions").DevTool | undefined} devtool the devtool option * @param {GenerateContext} generat
(cssSource, devtool, generateContext)
| 889 | * @returns {Source} a Source representing a JS string literal |
| 890 | */ |
| 891 | _cssToJsLiteral(cssSource, devtool, generateContext) { |
| 892 | const { source, map } = cssSource.sourceAndMap(); |
| 893 | let content = /** @type {string} */ (source); |
| 894 | if (map) { |
| 895 | const inlineMap = |
| 896 | typeof devtool === "string" && devtool.includes("nosources") |
| 897 | ? { ...map, sourcesContent: undefined } |
| 898 | : map; |
| 899 | const base64Map = Buffer.from(JSON.stringify(inlineMap), "utf8").toString( |
| 900 | "base64" |
| 901 | ); |
| 902 | const trailingNewline = content.endsWith("\n") ? "" : "\n"; |
| 903 | content += `${trailingNewline}/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}*/`; |
| 904 | } |
| 905 | |
| 906 | if (!content.includes(PUBLIC_PATH_FULL_HASH)) { |
| 907 | return new RawSource(JSON.stringify(content)); |
| 908 | } |
| 909 | |
| 910 | const result = new ConcatSource(); |
| 911 | let last = 0; |
| 912 | walkFullHashPlaceholders(content, (start, end, length) => { |
| 913 | result.add(JSON.stringify(content.slice(last, start))); |
| 914 | result.add( |
| 915 | length === 0 |
| 916 | ? ` + ${RuntimeGlobals.getFullHash}() + ` |
| 917 | : ` + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + ` |
| 918 | ); |
| 919 | last = end; |
| 920 | }); |
| 921 | |
| 922 | result.add(JSON.stringify(content.slice(last))); |
| 923 | generateContext.runtimeRequirements.add(RuntimeGlobals.getFullHash); |
| 924 | return result; |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * Generate the merged CSS text for a module, optionally wrapped as a |
no test coverage detected