faceyspacey / react-universal-component

🚀 The final answer to a React Universal Component: simultaneous SSR + Code Splitting
MIT License
1.7k stars 80 forks source link

chunkName not working? #200

Open Dagniele opened 4 years ago

Dagniele commented 4 years ago

Hi, I have a problem, I am trying to use a custom chunkName, but it does not seem to work, I tried with the babel-plugin-universal-import and without, no way, I don't know if I am doing something wrong, here is the basic piece of code:

const options = {
  render: (props: Props, Mod: any) => {
    if (!Mod) return <Loader iconSize={props.iconSize} />;

    const { iconSize, ...otherProps } = props;

    return <Mod {...otherProps} />;
  },
};

const asyncComponent = (props: Props) => import(`./icons/${allIcons[props.icon]}`);

export default universal(asyncComponent, options);

I tried to add in the options these properties:

const options = {
  ignoreBabelRename: true,
  chunkName: (props) => `whatever-${props.icon}`,
  render: (props: Props, Mod: any) => {
    if (!Mod) return <Loader iconSize={props.iconSize} />;

    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { iconSize, ...otherProps } = props;

    return <Mod {...otherProps} />;
  },
};

it does not work, tried to add the chunkName in the asyncLoader something similar to this:

const UniversalComponent = universal(props => universalImport({
  chunkName: props => props.page,
  path: props => path.join(__dirname, `./${props.page}`),
  resolve: props => require.resolveWeak(`./${props.page}`),
  load: props => Promise.all([
    import( /* webpackChunkName: '[request]' */ `./${props.page}`)
  ]).then(proms => proms[0])
}));

nothing seems to work, the output is always icons/MyIcon for example.