import { GetAssetsParams } from './types' ; import { isLoadableComponent } from './utils' ; import logger from 'razzle-dev-utils/logger' ; export const errorMeesage = `all async routes must have a chunkName property with value of /* webpackChunkName: "MyChunkName" */ check your routes config or use babel-plugin-after` ; export function getAssets ( { route , chunks } ) { let scripts = [ ] ; let styles = [ ] ; if ( ! route || ! isLoadableComponent ( route . component ) ) { return { scripts , styles } ; } const chunkName = route . component . getChunkName ( ) ; if ( chunkName === undefined ) { logger . error ( errorMeesage ) ; throw new Error ( ) ; } if ( chunks [ chunkName ] && chunks [ chunkName ] . js ) { scripts = chunks [ chunkName ] . js ; } if ( chunks [ chunkName ] && chunks [ chunkName ] . css ) { styles = chunks [ chunkName ] . css ; } return { scripts , styles } ; }