If you are NOT using babel-plugin-after, you must manually configure asyncComponent in your routes.js file to ensure assets are sent correctly. This requires two things:
- Adding a
/* webpackChunkName: "name" */ magic comment inside the import() statement. - Providing a
chunkName property in the asyncComponent configuration that matches the magic comment exactly.
Important: If the same component is used across different routes, the webpackChunkName and chunkName must be identical in all instances.
// routes.js
import Home from './Home';
import { asyncComponent } from '@jaredpalmer/after';
export default [
{
path: '/',
exact: true,
component: Home,
},
{
path: '/about',
exact: true,
component: asyncComponent({
loader: () => import(/* webpackChunkName: "whatever" */ './About'),
chunkName: 'whatever',
}),
},
{
path: '/contact-us',
exact: true,
component: asyncComponent({
loader: () => import(/* webpackChunkName: "ContactUs" */ './Contact'),
chunkName: 'ContactUs',
}),
},
];