| 41 | * @category Webpack Plugin |
| 42 | */ |
| 43 | export class AssetsPlugin implements WebpackPlugin { |
| 44 | /** |
| 45 | * Constructs new `AssetsPlugin`. |
| 46 | * |
| 47 | * @param config Plugin configuration options. |
| 48 | */ |
| 49 | constructor(private config: AssetsPluginConfig) { |
| 50 | this.config.configureLoader = this.config.configureLoader ?? true; |
| 51 | this.config.extensions = this.config.extensions ?? ASSET_EXTENSIONS; |
| 52 | this.config.scalableExtensions = |
| 53 | this.config.scalableExtensions ?? SCALABLE_ASSETS; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Apply the plugin. |
| 58 | * |
| 59 | * @param compiler Webpack compiler instance. |
| 60 | */ |
| 61 | apply(compiler: webpack.Compiler) { |
| 62 | const assetResolver = new AssetResolver(this.config, compiler); |
| 63 | |
| 64 | if (this.config.configureLoader) { |
| 65 | compiler.options.module.rules.push({ |
| 66 | test: getAssetExtensionsRegExp(assetResolver.config.extensions!), |
| 67 | use: [ |
| 68 | { |
| 69 | loader: require.resolve('../../../assets-loader.js'), |
| 70 | options: { |
| 71 | platform: this.config.platform, |
| 72 | scalableAssetExtensions: SCALABLE_ASSETS, |
| 73 | devServerEnabled: this.config.devServerEnabled, |
| 74 | }, |
| 75 | }, |
| 76 | ], |
| 77 | }); |
| 78 | } |
| 79 | compiler.options.resolve.plugins = ( |
| 80 | compiler.options.resolve.plugins || [] |
| 81 | ).concat(assetResolver); |
| 82 | } |
| 83 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…