Reputation: 4715
I have a simple react project that uses webpack. When calling npm run build
it creates a collection of files that needs to be uploaded to the webserver to become available to the public.
My question is: is there way to instruct webpack to produce a distribution that downloads the react.js from some official react cdn?
the goal is to make my website download faster if users already have react in their browser cache
Upvotes: 0
Views: 489
Reputation: 1126
Use Webpack externals
for this.
Like the documentation says:
The externals configuration option provides a way of excluding dependencies from the output bundles. Instead, the created bundle relies on that dependency to be present in the consumer's environment.
module.exports = {
//...
externals: [
{
react: 'react',
}
]
};
And put the link to the latest react in the html page. Works fine.
Upvotes: 3