Trigger script on React hot refresh or after file creation

  create-react-app, javascript, node.js, reactjs

I am trying to add some code generation for my current project, and to implement this I want to trigger a node script after each change, right before React does recompile and hot reloading, so this script can check if certain files have been changed and generate output, so React can recompile taking this output into consideration.

My question is this possible? and if yes, how can I implement it?

For example i already have file

export default class A extends Component {
  constructor(props){
    this.name = "A"          
  }    
}

and I have generated file

export default class Generated {
  getComponent(name){
     if(name==="A") return new A();
  }
}

now i add file

export default class B extends Component {
  constructor(props){
    this.name = "B"          
  }    
}

And i want to trigger my codegeneration script, so it will alter Generated class like this:

export default class Generated {
  getComponent(name){
     if(name==="A") return new A();
     else if(name==="B") return new B();
  }
}

Thanks in advance!

Source: Ask Javascript Questions

LEAVE A COMMENT