import webpack from 'webpack' ; import type Config from 'webpack-chain' ; import path from 'path' ; import { existsSync } from 'fs-extra' ; import findCacheDir from 'find-cache-dir' ; import resolve from '../blocks/resolve' ; import ignoreLocales from '../blocks/ignoreLocales' ; import type { ConfigManager } from '../../../config/configManager' ; import { safeRequireResolve } from '../../../utils/safeRequire' ; const filterNonExisted = ( filePaths ) => { return filePaths . filter ( ( filePath ) => { return filePath && existsSync ( filePath ) ; } ) ; } ; export default ( configManager ) => ( config ) => { const env = configManager . env === 'development' ? 'dev' : 'prod' ; const { postcss : { config : postcssConfig } = { } } = configManager . build . configurations ; config . context ( path . resolve ( __dirname , '..' , '..' , '..' , '..' ) ) ; config . batch ( resolve ( configManager ) ) ; config . batch ( ignoreLocales ( ) ) ; config . resolve . symlinks ( configManager . resolveSymlinks ) . end ( ) ; config . optimization . set ( 'checkWasmTypes' , false ) ; config . output . merge ( { environment : { arrowFunction : false } } ) ; config . output . set ( 'strictModuleExceptionHandling' , true ) ; config . output . set ( 'hashFunction' , 'xxhash64' ) ; config . cache ( { type : 'filesystem' , name : `${ env }-${ configManager . type }-${ configManager . buildType }-${ configManager . name }${ configManager . buildType === 'client' && configManager . modern ? '-modern' : '' }` , cacheDirectory : findCacheDir ( { cwd : configManager . rootDir , name : 'webpack' } ) , buildDependencies : { cli : [ '@tramvai/cli' ] , webpack : [ 'webpack/lib' ] , config : filterNonExisted ( [ path . resolve ( configManager . rootDir , 'tramvai.json' ) ] ) , css : filterNonExisted ( [ postcssConfig && safeRequireResolve ( path . resolve ( configManager . rootDir , postcssConfig ) ) , ] ) , } , } ) ; config . set ( 'snapshot' , { managedPaths : [ ] , } ) ; config . set ( 'experiments' , configManager . experiments . webpack ?? { } ) ; config . mode ( 'development' ) . optimization . minimize ( false ) . splitChunks ( false ) . end ( ) . plugin ( 'define' ) . use ( webpack . DefinePlugin , [ { ... configManager . build . configurations . definePlugin [ env ] , 'process.env.APP_ID' : JSON . stringify ( configManager . name || 'common' ) , 'process.env.APP_VERSION' : JSON . stringify ( process . env . APP_VERSION ) , 'process.env.ENABLE_DEVTOOLS' : process . env . ENABLE_DEVTOOLS || configManager . env === 'development' , 'process.env.DISABLE_EXTERNAL_SCRIPTS' : process . env . DISABLE_EXTERNAL_SCRIPTS || false , } , ] ) ; return config ; } ;