MCPcopy
hub / github.com/callstack/repack / apply

Method apply

packages/repack/src/webpack/plugins/TargetPlugin.ts:20–97  ·  view source on GitHub ↗

* Apply the plugin. * * @param compiler Webpack compiler instance.

(compiler: webpack.Compiler)

Source from the content-addressed store, hash-verified

18 * @param compiler Webpack compiler instance.
19 */
20 apply(compiler: webpack.Compiler) {
21 compiler.options.target = false;
22 compiler.options.output.chunkLoading = 'jsonp';
23 compiler.options.output.chunkFormat = 'array-push';
24 compiler.options.output.globalObject = 'self';
25
26 new webpack.NormalModuleReplacementPlugin(
27 /react-native([/\\]+)Libraries([/\\]+)Utilities([/\\]+)HMRClient\.js$/,
28 function (resource) {
29 const request = require.resolve(
30 '../../client/setup/modules/DevServerClient'
31 );
32 const context = path.dirname(request);
33 resource.request = request;
34 resource.context = context;
35 resource.createData.resource = request;
36 resource.createData.context = context;
37 }
38 ).apply(compiler);
39
40 // Overwrite `LoadScriptRuntimeModule.generate` to avoid shipping DOM specific
41 // code in the bundle. `__webpack_require__.l` implementation is provided
42 // in `../../../runtime/setupChunkLoader.ts`.
43 webpack.runtime.LoadScriptRuntimeModule.prototype.generate = function () {
44 return webpack.Template.asString([
45 `${webpack.RuntimeGlobals.loadScript} = function(u, c, n, i) {`,
46 webpack.Template.indent(
47 `return __repack__.loadChunk.call(this, u, c, n, i, "${this.chunk.id}");`
48 ),
49 '};',
50 ]);
51 };
52
53 const renderBootstrap =
54 webpack.javascript.JavascriptModulesPlugin.prototype.renderBootstrap;
55 webpack.javascript.JavascriptModulesPlugin.prototype.renderBootstrap =
56 function (...args) {
57 const result = renderBootstrap.call(this, ...args);
58 result.afterStartup.push('');
59 result.afterStartup.push('// Re.Pack after startup');
60 result.afterStartup.push(
61 `__repack__.loadChunkCallback.push("${args[0].chunk.id}")`
62 );
63 return result;
64 };
65
66 compiler.hooks.environment.tap('TargetPlugin', () => {
67 new webpack.BannerPlugin({
68 raw: true,
69 entryOnly: true,
70 banner: getRepackBootstrap({
71 chunkLoadingGlobal: compiler.options.output.chunkLoadingGlobal!,
72 }),
73 }).apply(compiler);
74 });
75
76 compiler.hooks.compilation.tap('TargetPlugin', (compilation) => {
77 compilation.hooks.afterProcessAssets.tap('TargetPlugin', () => {

Callers

nothing calls this directly

Calls 2

getRepackBootstrapFunction · 0.90
applyMethod · 0.65

Tested by

no test coverage detected