api.cache(true)在Expo的babel.config.js中做什么?

时间:2018-12-12 00:50:23

标签: javascript reactjs react-native babeljs expo

此行出现在默认的Expo babel.config.js中,但是我在任何地方都找不到它的功能。有谁知道这是做什么的吗?

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

1 个答案:

答案 0 :(得分:0)

默认情况下,Babel每次处理新文件时都会评估配置。通过缓存配置函数执行结果可以优化构建过程的性能。 public function selectquestion($id){ $max = $id + 4;//max selected value $params = array(); $arr = array(); $count = 1; for($i=$id; $i<=$max; $i++) { $arr[$count] = $i;//generates all numbers between min and max $params[$count] = ':p_'.$count; $count++; } $range_param = implode(",",$params); $sql = $this->pdo->prepare("SELECT questions.value,questions.file,questions.img,options.option1,options.option2,options.option3,options.option4,options.answer FROM options INNER JOIN questions ON questions.id = options.q_id WHERE questions.id >= :id AND questions.id <= :max AND questions.id IN ($range_param)");//selects all of questions and options where condition is true $sql->bindParam(':id', $id, PDO::PARAM_INT); $sql->bindParam(':max', $max, PDO::PARAM_INT); foreach($arr as $key => $a){ $sql->bindParam(':p_'.$key, $arr[$key], PDO::PARAM_INT); } $sql->execute(); $row = $sql->fetchAll(PDO::FETCH_OBJ); return$row; } var_dump($options = $obj->selectquestion(2)); 就是这么做的。通过这种方式启用缓存后,配置函数将仅被调用一次。

以下是有关Babel配置缓存的更详细说明的链接:https://babeljs.io/docs/en/config-files#apicache