import { ASYNC_SCRIPTS , HASH_NAME_PROD , MP_ASSETS } from '../../config/constants' ; import { WebpackOutput , BalmScripts } from '@balm-core/index' ; function getFilename ( scripts , isChunk = false ) { let filename ; if ( isChunk ) { filename = BalmJS . config . env . isProd ? `[name].${ HASH_NAME_PROD }` : '[name]' ; } else { filename = scripts . useCache ? `[name].${ HASH_NAME_PROD }` : '[name]' ; } return `${ filename }.js` ; } function getOutput ( output , scripts , isHook = false ) { const outputPath = output || BalmJS . config . dest . base ; const jsFolder = BalmJS . config . paths . target . js ; const jsFilename = getFilename ( scripts ) ; const jsChunkFilename = getFilename ( scripts , true ) ; const customLibraryConfig = scripts . library ? { library : scripts . library } : { } ; const miniprogramConfig = BalmJS . config . env . isMP ? { path : BalmJS . file . absPath ( path . join ( BalmJS . config . dest . base , MP_ASSETS ) ) , library : 'createApp' , libraryExport : 'default' , libraryTarget : 'window' } : { } ; return Object . assign ( { path : BalmJS . file . absPath ( outputPath ) , filename : isHook ? jsFilename : BalmJS . file . assetsPath ( `${ jsFolder }/${ jsFilename }` ) , publicPath : BalmJS . file . publicUrlOrPath , chunkFilename : isHook ? jsChunkFilename : BalmJS . file . assetsPath ( `${ jsFolder }/${ ASYNC_SCRIPTS }/${ jsChunkFilename }` ) , libraryTarget : scripts . libraryTarget } , customLibraryConfig , miniprogramConfig ) ; } export default getOutput ;