perf: avoid loadFullConfig when creating block hoist plugin (#13223)
* perf: avoid loadFullConfig when creating block hoist plugin * address code review comments
This commit is contained in:
parent
a0e20ac5df
commit
88da2e80ed
@ -1,22 +1,18 @@
|
||||
import loadConfig from "../config";
|
||||
|
||||
import type { Plugin } from "../config";
|
||||
import traverse from "@babel/traverse";
|
||||
import Plugin from "../config/plugin";
|
||||
|
||||
let LOADED_PLUGIN: Plugin | void;
|
||||
|
||||
export default function loadBlockHoistPlugin(): Plugin {
|
||||
if (!LOADED_PLUGIN) {
|
||||
// Lazy-init the internal plugin to remove the init-time circular
|
||||
// dependency between plugins being passed @babel/core's export object,
|
||||
// which loads this file, and this 'loadConfig' loading plugins.
|
||||
const config = loadConfig.sync({
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
browserslistConfigFile: false,
|
||||
plugins: [blockHoistPlugin],
|
||||
});
|
||||
LOADED_PLUGIN = config ? config.passes[0][0] : undefined;
|
||||
if (!LOADED_PLUGIN) throw new Error("Assertion failure");
|
||||
// cache the loaded blockHoist plugin plugin
|
||||
LOADED_PLUGIN = new Plugin(
|
||||
{
|
||||
...blockHoistPlugin,
|
||||
visitor: traverse.explode(blockHoistPlugin.visitor),
|
||||
},
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
return LOADED_PLUGIN;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user