'using webpack to import files dynamically inside react component
const LongDetail: React.FC<Props> = ({
id,
section,
placeholder,
Fromtolocation,
}) => {
const {
setPrimary,
setSecondary,
createDescContent,
setDescContent,
setDescHeading,
} = require(`../../store/resume/long-details/${section}`);
... ***some component logic***
}
i know webpack finds all the imports and requires statements first, then loads these modules first before compiling our react app, can i use any plugin so that webpack loads only the required file?
to do this it'll have to
- load the required file after our app is rendered or
- i can pass an array of files to be loaded during the bundling which will be loaded only once and then one of those files is imported based on the condition.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|