MCPcopy Create free account
hub / github.com/agent-tower/core / configureWebpack

Function configureWebpack

packages/docs-site/plugins/resolve-weak-fallback.cjs:4–51  ·  view source on GitHub ↗
(_config, isServer)

Source from the content-addressed store, hash-verified

2 return {
3 name: 'resolve-weak-fallback',
4 configureWebpack(_config, isServer) {
5 if (!isServer) {
6 return {};
7 }
8
9 return {
10 plugins: [
11 {
12 apply(compiler) {
13 const { Compilation, sources } = compiler.webpack;
14
15 compiler.hooks.thisCompilation.tap('resolve-weak-fallback', (compilation) => {
16 compilation.hooks.processAssets.tap(
17 {
18 name: 'resolve-weak-fallback',
19 stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
20 },
21 () => {
22 for (const assetName of Object.keys(compilation.assets)) {
23 if (!assetName.endsWith('.js')) continue;
24
25 const asset = compilation.getAsset(assetName);
26 if (!asset) continue;
27
28 const source = asset.source.source().toString();
29 if (!source.includes('require.resolveWeak(')) {
30 continue;
31 }
32
33 let patchedSource = source;
34 if (patchedSource.includes('prism-include-languages')) {
35 patchedSource = patchedSource.replace(
36 /\/\* harmony default export \*\/ const __WEBPACK_DEFAULT_EXPORT__ = \(\[require\([^;]+;\n/,
37 '/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ([]);\n'
38 );
39 }
40 patchedSource = patchedSource.replace(/require\.resolveWeak\("([^"]+)"\)/g, 'undefined');
41
42 compilation.updateAsset(assetName, new sources.RawSource(patchedSource));
43 }
44 }
45 );
46 });
47 },
48 },
49 ],
50 };
51 },
52 };
53}
54

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected