* Applies the plugin. * @param {import('webpack').Compiler} compiler A webpack compiler object. * @returns {void}
(compiler)
| 33 | * @returns {void} |
| 34 | */ |
| 35 | apply(compiler) { |
| 36 | // Skip processing in non-development mode, but allow manual force-enabling |
| 37 | if ( |
| 38 | // Webpack do not set process.env.NODE_ENV, so we need to check for mode. |
| 39 | // Ref: https://github.com/webpack/webpack/issues/7074 |
| 40 | (compiler.options.mode !== 'development' || |
| 41 | // We also check for production process.env.NODE_ENV, |
| 42 | // in case it was set and mode is non-development (e.g. 'none') |
| 43 | (process.env.NODE_ENV && process.env.NODE_ENV === 'production')) && |
| 44 | !this.options.forceEnable |
| 45 | ) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | const logger = compiler.getInfrastructureLogger(this.constructor.name); |
| 50 | |
| 51 | // Get Webpack imports from compiler instance (if available) - |
| 52 | // this allow mono-repos to use different versions of Webpack without conflicts. |
| 53 | const webpack = compiler.webpack || require('webpack'); |
| 54 | const { |
| 55 | DefinePlugin, |
| 56 | EntryDependency, |
| 57 | EntryPlugin, |
| 58 | ModuleFilenameHelpers, |
| 59 | NormalModule, |
| 60 | ProvidePlugin, |
| 61 | RuntimeGlobals, |
| 62 | Template, |
| 63 | } = webpack; |
| 64 | |
| 65 | // Inject react-refresh context to all Webpack entry points. |
| 66 | const { overlayEntries, prependEntries } = getAdditionalEntries(this.options); |
| 67 | // Prepended entries does not care about injection order, |
| 68 | // so we can utilise EntryPlugin for simpler logic. |
| 69 | for (const entry of prependEntries) { |
| 70 | new EntryPlugin(compiler.context, entry, { name: undefined }).apply(compiler); |
| 71 | } |
| 72 | |
| 73 | const integrationEntry = getIntegrationEntry(this.options.overlay.sockIntegration); |
| 74 | const socketEntryData = []; |
| 75 | compiler.hooks.make.tap( |
| 76 | { name: this.constructor.name, stage: Number.POSITIVE_INFINITY }, |
| 77 | (compilation) => { |
| 78 | // Exhaustively search all entries for `integrationEntry`. |
| 79 | // If found, mark those entries and the index of `integrationEntry`. |
| 80 | for (const [name, entryData] of compilation.entries.entries()) { |
| 81 | const index = entryData.dependencies.findIndex( |
| 82 | (dep) => dep.request && dep.request.includes(integrationEntry) |
| 83 | ); |
| 84 | if (index !== -1) { |
| 85 | socketEntryData.push({ name, index }); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | ); |
| 90 | |
| 91 | // Overlay entries need to be injected AFTER integration's entry, |
| 92 | // so we will loop through everything in `finishMake` instead of `make`. |
no test coverage detected