src/runServer.js
function readWebpackConfig( server ) {

  const devConfig = server.webpackConfig && server.webpackConfig.dev;
  const configFile = paths.resolveApp( devConfig ) || appWebpackDevConfig;

  try {

    assert(
      existsSync( configFile ),
      `File ${devConfig || WEBPACK_DEV_CONFIG} is not exsit.`
    );

    const wpConfig = getConfig( configFile );

    // plugins: function
    if ( is.Function( wpConfig.plugins )) {
      wpConfig.plugins = wpConfig.plugins( wpConfig );
    }

    // plugins: not array
    if ( !is.Array( wpConfig.plugins )) {
      wpConfig.plugins = [wpConfig.plugins];
    }

    // plugins: array in array
    wpConfig.plugins = flatten( wpConfig.plugins.map(( plugin ) => {
      return is.Function( plugin ) ? plugin( wpConfig ) : plugin;
    }));

    server.webpackDevConfig = wpConfig;
    watchFiles.push( configFile );

    return Right( server );
  } catch ( e ) {
    print(
      chalk.red( `Failed to read ${devConfig || WEBPACK_DEV_CONFIG}.` ),
      e.message
    );
    print();
    return Left( null );
  }
}
function readWebpackConfig( server ) {

  const devConfig = server.webpackConfig && server.webpackConfig.dev;
  const configFile = paths.resolveApp( devConfig ) || appWebpackDevConfig;

  try {

    assert(
      existsSync( configFile ),
      `File ${devConfig || WEBPACK_DEV_CONFIG} is not exsit.`
    );

    const wpConfig = getConfig( configFile );

    // plugins: function
    if ( is.Function( wpConfig.plugins )) {
      wpConfig.plugins = wpConfig.plugins( wpConfig );
    }

    // plugins: not array
    if ( !is.Array( wpConfig.plugins )) {
      wpConfig.plugins = [wpConfig.plugins];
    }

    // plugins: array in array
    wpConfig.plugins = flatten( wpConfig.plugins.map(( plugin ) => {
      return is.Function( plugin ) ? plugin( wpConfig ) : plugin;
    }));

    server.webpackDevConfig = wpConfig;
    watchFiles.push( configFile );

    return Right( server );
  } catch ( e ) {
    print(
      chalk.red( `Failed to read ${devConfig || WEBPACK_DEV_CONFIG}.` ),
      e.message
    );
    print();
    return Left( null );
  }
}
function readWebpackConfig ( server ) { const devConfig = server . webpackConfig && server . webpackConfig . dev ; const configFile = paths . resolveApp ( devConfig ) || appWebpackDevConfig ; try { assert ( existsSync ( configFile ) , ` ${ devConfig || WEBPACK_DEV_CONFIG } ` ) ; const wpConfig = getConfig ( configFile ) ; // plugins: function if ( is . Function ( wpConfig . plugins ) ) { wpConfig . plugins = wpConfig . plugins ( wpConfig ) ; } // plugins: not array if ( ! is . Array ( wpConfig . plugins ) ) { wpConfig . plugins = [ wpConfig . plugins ] ; } // plugins: array in array wpConfig . plugins = flatten ( wpConfig . plugins . map ( ( plugin ) => { return is . Function ( plugin ) ? plugin ( wpConfig ) : plugin ; } ) ) ; server . webpackDevConfig = wpConfig ; watchFiles . push ( configFile ) ; return Right ( server ) ; } catch ( e ) { print ( chalk . red ( ` ${ devConfig || WEBPACK_DEV_CONFIG } ` ) , e . message ) ; print ( ) ; return Left ( null ) ; } }
read config for webpack dev server
read config for webpack dev server