Reputation: 2661
I am reading a file into my React component like this:
let SVN_VERSION;
try{
SVN_VERSION = require("./svnversion.txt");
}catch(e){}
...
async componentDidMount(){
if(!SVN_VERSION) return;
const res = await fetch(SVN_VERSION);
const svnVersion = await res.text();
this.setState({svnVersion})
}
This works fine on my local machine. When I change the content of the file, the component gets updated.
However, after I built the project with npm run build
it doesn't get updated anymore. It just takes the content at built time.
I was wondering how I could make it so that it dynamically reads the content of the file?
Upvotes: 1
Views: 615
Reputation: 2595
I created project with create-react-app and the component still updated dynamically with the content in the file after I built. Can you post your webpack config, your build folder structure or your full code?
Below is my build folder
Upvotes: 1