( loaderContext: webpack.LoaderContext<LoaderOptions> )
| 10 | let loaderUtils: LoaderUtilsModule | undefined; |
| 11 | |
| 12 | export function getOptions( |
| 13 | loaderContext: webpack.LoaderContext<LoaderOptions> |
| 14 | ) { |
| 15 | if (isWebpack5) { |
| 16 | return loaderContext.getOptions(); |
| 17 | } |
| 18 | |
| 19 | if (!loaderUtils) { |
| 20 | try { |
| 21 | loaderUtils = module.require('loader-utils') as LoaderUtilsModule; |
| 22 | } catch { |
| 23 | throw new Error( |
| 24 | 'ts-loader requires loader-utils to be installed when used with webpack 4.' |
| 25 | ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | return loaderUtils.getOptions<LoaderOptions>(loaderContext as any) || ({} as LoaderOptions); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * webpack 4 and webpack 5 have different APIs for adding errors to modules. This function abstracts that away. |
nothing calls this directly
no test coverage detected