nl_tokens: Initialize build options 初始化构建配置
pl_tokens: function initBuildOptions ( appType , options , cliOpts = { } ) { appType = cliOpts . type || appType || 'swan' ; let userConfig = getUserBuildConfig ( options , appType , cliOpts . config ) ; let userOutputFile = userConfig . output && userConfig . output . file ; // merge user config with default config let buildConf = getDefaultBuildConfig ( appType ) ; let rawBaseOutputFile = buildConf . output && buildConf . output . file ; buildConf = merge ( { } , buildConf , userConfig , { appType } ) ; let { watch : watchMode , server : serverMode , port } = cliOpts || { } ; if ( watchMode ) { ! buildConf . watch && ( buildConf . watch = true ) ; } else { buildConf . watch = false ; } if ( serverMode ) { port && ( port = parseInt ( port , 10 ) ) ; let serverConf = buildConf . server || { } ; port && ( serverConf . port = port ) ; buildConf . server = serverConf ; } else { buildConf . server = false ; } const rootDir = path . resolve ( process . cwd ( ) , buildConf . root || '.' ) ; buildConf . root = rootDir ; // init output config let outputOpts = buildConf . output ; let outputDir = <mask> . resolve ( rootDir , outputOpts . dir || 'dist' ) ; buildConf . output = Object . assign ( { } , outputOpts , { dir : outputDir } ) ; // for user custom file output providing extra raw output file filter handler let superOutputFile = function ( ... args ) { return rawBaseOutputFile && rawBaseOutputFile . apply ( this , args ) ; } ; if ( userOutputFile ) { buildConf . output . file = function ( ... args ) { return userOutputFile . apply ( this , args . concat ( superOutputFile . bind ( this , ... args ) ) ) ; } ; } // init logger let { logger , logLevel } = buildConf ; buildConf . logger = initLogger ( logger , logLevel , userConfig ) ; // add logger to global if ( ! global . okamLogger ) { global . okamLogger = buildConf . logger ; } // init polyfill options let { localPolyfill , polyfill } = buildConf ; let polyfillConf = normalizePolyfill ( localPolyfill || polyfill , rootDir , buildConf . logger ) ; buildConf [ localPolyfill ? 'localPolyfill' : 'polyfill' ] = polyfillConf ; return buildConf ; }