File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import type {
1919 LogLevel ,
2020 TSInstance ,
2121} from './interfaces' ;
22+ import { getWebpack4LoaderOptions } from './loaderUtils' ;
2223import {
2324 appendSuffixesIfMatch ,
2425 arrify ,
@@ -29,11 +30,6 @@ import type { RawSourceMap } from 'source-map';
2930import { SourceMapConsumer , SourceMapGenerator } from 'source-map' ;
3031
3132const loaderOptionsCache : LoaderOptionsCache = { } ;
32- const requireFromTsLoader = module . require . bind ( module ) as NodeJS . Require ;
33- type LoaderUtilsModule = {
34- getOptions < T > ( loaderContext : { query : string } ) : T ;
35- } ;
36- let loaderUtils : LoaderUtilsModule | undefined ;
3733
3834/**
3935 * The entry point for ts-loader
@@ -241,22 +237,6 @@ function getLoaderOptions(
241237 return options ;
242238}
243239
244- function getWebpack4LoaderOptions (
245- loaderContext : webpack . LoaderContext < LoaderOptions >
246- ) {
247- if ( ! loaderUtils ) {
248- try {
249- loaderUtils = requireFromTsLoader ( 'loader-utils' ) as LoaderUtilsModule ;
250- } catch {
251- throw new Error (
252- 'ts-loader requires loader-utils to be installed when used with webpack 4.'
253- ) ;
254- }
255- }
256-
257- return loaderUtils . getOptions < LoaderOptions > ( loaderContext as any ) || ( { } as LoaderOptions ) ;
258- }
259-
260240type ValidLoaderOptions = keyof LoaderOptions ;
261241const validLoaderOptions : ValidLoaderOptions [ ] = [
262242 'silent' ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import type * as webpack from 'webpack' ;
2+
3+ import type { LoaderOptions } from './interfaces' ;
4+
5+ const requireFromTsLoader = module . require . bind ( module ) as NodeJS . Require ;
6+ type LoaderUtilsModule = {
7+ getOptions < T > ( loaderContext : { query : string } ) : T ;
8+ } ;
9+ let loaderUtils : LoaderUtilsModule | undefined ;
10+
11+ export function getWebpack4LoaderOptions (
12+ loaderContext : webpack . LoaderContext < LoaderOptions >
13+ ) {
14+ if ( ! loaderUtils ) {
15+ try {
16+ loaderUtils = requireFromTsLoader ( 'loader-utils' ) as LoaderUtilsModule ;
17+ } catch {
18+ throw new Error (
19+ 'ts-loader requires loader-utils to be installed when used with webpack 4.'
20+ ) ;
21+ }
22+ }
23+
24+ return loaderUtils . getOptions < LoaderOptions > ( loaderContext as any ) || ( { } as LoaderOptions ) ;
25+ }
You can’t perform that action at this time.
0 commit comments