import { CustomWebpackBrowserSchema , TargetOptions } from '@angular-builders/custom-webpack' ; import * as webpack from 'webpack' ; import * as pkg from '../src/package.json' ; export default ( config , options , targetOptions ) => { config . resolveLoader = { ... config . resolveLoader , alias : { 'code-snippet-loader' : './configs/loaders/code-snippet-loader.js' , 'markdown-highlighter-loader' : './configs/loaders/markdown-highlighter-loader.js' , } , } ; const extensions = [ '.html' , '.js' , '.css' , '.ts' ] ; for ( const rule of config . module . rules ?? [ ] ) { const webpackRule = rule as webpack . RuleSetRule ; if ( webpackRule . test instanceof RegExp ) { const test = webpackRule . test as RegExp ; if ( extensions . some ( ext => test . test ( ext ) ) ) { webpackRule . exclude = /(snippets|templates)/ ; } } } config . module . rules . push ( { test : /\.(html|js|css|ts)$/ , include : /snippets/ , use : 'code-snippet-loader' , } ) ; config . module . rules . push ( { test : /\.txt$/ , type : 'asset/source' } ) ; config . module . rules . push ( { test : /\.md$/ , use : [ { loader : 'html-loader' , options : { esModule : false } , } , 'markdown-highlighter-loader' , ] , } ) ; config . module . rules . push ( { test : /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|otf|mp4|mp3|vtt)$/ , type : 'asset/resource' , } ) ; config . plugins . push ( new webpack . DefinePlugin ( { VERSION : JSON . stringify ( pkg . version ) , PRODUCTION : targetOptions . configuration === 'production' , } ) ) ; return config ; } ;