| 33 | * @category Webpack Plugin |
| 34 | */ |
| 35 | export class OutputPlugin implements WebpackPlugin { |
| 36 | /** |
| 37 | * Constructs new `OutputPlugin`. |
| 38 | * |
| 39 | * @param config Plugin configuration options. |
| 40 | */ |
| 41 | constructor(private config: OutputPluginConfig) { |
| 42 | if (!this.config.platform) { |
| 43 | throw new Error('Missing `platform` option in `OutputPlugin`'); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Apply the plugin. |
| 49 | * |
| 50 | * @param compiler Webpack compiler instance. |
| 51 | */ |
| 52 | apply(compiler: webpack.Compiler) { |
| 53 | const cliOptions: CliOptions | null = JSON.parse( |
| 54 | process.env[CLI_OPTIONS_ENV_KEY] ?? 'null' |
| 55 | ); |
| 56 | |
| 57 | // Noop when running from Webpack CLI or when running with dev server |
| 58 | if ( |
| 59 | !cliOptions || |
| 60 | 'start' in cliOptions.arguments || |
| 61 | this.config.devServerEnabled |
| 62 | ) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | const logger = compiler.getInfrastructureLogger('ReactNativeOutputPlugin'); |
| 67 | |
| 68 | const args = cliOptions.arguments.bundle; |
| 69 | let { bundleOutput, assetsDest = '', sourcemapOutput = '' } = args; |
| 70 | if (!path.isAbsolute(bundleOutput)) { |
| 71 | bundleOutput = path.join(cliOptions.config.root, bundleOutput); |
| 72 | } |
| 73 | const bundleOutputDir = path.dirname(bundleOutput); |
| 74 | |
| 75 | if (!sourcemapOutput) { |
| 76 | sourcemapOutput = `${bundleOutput}.map`; |
| 77 | } |
| 78 | if (!path.isAbsolute(sourcemapOutput)) { |
| 79 | sourcemapOutput = path.join(cliOptions.config.root, sourcemapOutput); |
| 80 | } |
| 81 | |
| 82 | if (!assetsDest) { |
| 83 | assetsDest = bundleOutputDir; |
| 84 | } |
| 85 | |
| 86 | let remoteChunksOutput = this.config.remoteChunksOutput; |
| 87 | if (remoteChunksOutput && !path.isAbsolute(remoteChunksOutput)) { |
| 88 | remoteChunksOutput = path.join( |
| 89 | cliOptions.config.root, |
| 90 | remoteChunksOutput |
| 91 | ); |
| 92 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…