MCPcopy
hub / github.com/webpack/sass-loader / getCodeFromBundle

Function getCodeFromBundle

test/helpers/getCodeFromBundle.js:11–35  ·  view source on GitHub ↗

* @param {Stats} stats stats * @param {Compiler} compiler compiler * @param {name} asset asset name * @returns {Record } code from bundle

(stats, compiler, asset)

Source from the content-addressed store, hash-verified

9 * @returns {Record<string, string>} code from bundle
10 */
11function getCodeFromBundle(stats, compiler, asset) {
12 let code = null;
13
14 if (
15 stats &&
16 stats.compilation &&
17 stats.compilation.assets &&
18 stats.compilation.assets[asset || "main.bundle.js"]
19 ) {
20 code = readAsset(asset || "main.bundle.js", compiler, stats);
21 }
22
23 if (!code) {
24 throw new Error("Can't find compiled code");
25 }
26
27 const result = vm.runInNewContext(
28 `${code};\nmodule.exports = sassLoaderExport;`,
29 {
30 module: {},
31 },
32 );
33
34 return result.default;
35}
36
37export default getCodeFromBundle;

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…