gating
gating ãªãã·ã§ã³ã¯æ¡ä»¶ä»ãã³ã³ãã€ã«ãæå¹ã«ããæé©åãããã³ãŒããã©ã³ã¿ã€ã ã§ãã€äœ¿çšããããå¶åŸ¡ã§ããããã«ããŸãã
{
gating: {
source: 'my-feature-flags',
importSpecifierName: 'shouldUseCompiler'
}
}ãªãã¡ã¬ã³ã¹
gating
ã³ã³ãã€ã«ããã颿°ã«å¯Ÿãããã©ã³ã¿ã€ã ã®ãã£ãŒãã£ãŒãã©ã°ã«ããå¶åŸ¡ãèšå®ããŸãã
å
{
source: string;
importSpecifierName: string;
} | nullããã©ã«ãå€
null
ããããã£
source: ãã£ãŒãã£ãŒãã©ã°ãã€ã³ããŒãããã¢ãžã¥ãŒã«ãã¹importSpecifierName: ã€ã³ããŒããããšã¯ã¹ããŒãæžã¿é¢æ°ã®åå
泚æç¹
- ã²ãŒãã£ã³ã°é¢æ°ã¯ããŒãªã¢ã³ãè¿ãå¿ èŠããããŸãã
- ã³ã³ãã€ã«æžã¿ããŒãžã§ã³ãšå ã®ããŒãžã§ã³ã®äž¡æ¹ãå«ããããããã³ãã«ãµã€ãºãå¢å ããŸãã
- ã³ã³ãã€ã«ããã颿°ãå«ããã¹ãŠã®ãã¡ã€ã«ã«ã€ã³ããŒãæãä»å ãããŸãã
äœ¿çšæ³
åºæ¬çãªãã£ãŒãã£ãŒãã©ã°ã®ã»ããã¢ãã
- ãã£ãŒãã£ãŒãã©ã°ã¢ãžã¥ãŒã«ãäœæããŸãã
// src/utils/feature-flags.js
export function shouldUseCompiler() {
// your logic here
return getFeatureFlag('react-compiler-enabled');
}- ã³ã³ãã€ã©ãèšå®ããŸãã
{
gating: {
source: './src/utils/feature-flags',
importSpecifierName: 'shouldUseCompiler'
}
}- ã³ã³ãã€ã©ãã²ãŒãã£ã³ã°æžã¿ã®ã³ãŒããçæããŸãã
// Input
function Button(props) {
return <button>{props.label}</button>;
}
// Output (simplified)
import { shouldUseCompiler } from './src/utils/feature-flags';
const Button = shouldUseCompiler()
? function Button_optimized(props) { /* compiled version */ }
: function Button_original(props) { /* original version */ };ã²ãŒãã£ã³ã°é¢æ°ã¯ã¢ãžã¥ãŒã«è©äŸ¡æã«äžåºŠã ãè©äŸ¡ãããããšã«æ³šæããŠãã ãããJS ãã³ãã«ãããŒã¹ã»è©äŸ¡ãããæç¹ã§ã³ã³ããŒãã³ãã®éžæãåºå®ããããã©ãŠã¶ã»ãã·ã§ã³ãæç¶ããéãéçã«ç¶æãããŸãã
ãã©ãã«ã·ã¥ãŒãã£ã³ã°
ãã£ãŒãã£ãŒãã©ã°ãåäœããªã
ãã©ã°ã¢ãžã¥ãŒã«ãæ£ãã颿°ããšã¯ã¹ããŒãããŠããã確èªããŠãã ããã
// â Wrong: Default export
export default function shouldUseCompiler() {
return true;
}
// â
Correct: Named export matching importSpecifierName
export function shouldUseCompiler() {
return true;
}ã€ã³ããŒããšã©ãŒãçºçãã
ãœãŒã¹ã®ãã¹ãæ£ããããšã確èªããŠãã ããã
// â Wrong: Relative to babel.config.js
{
source: './src/flags',
importSpecifierName: 'flag'
}
// â
Correct: Module resolution path
{
source: '@myapp/feature-flags',
importSpecifierName: 'flag'
}
// â
Also correct: Absolute path from project root
{
source: './src/utils/flags',
importSpecifierName: 'flag'
}