ctrlplusb / react-async-component

Resolve components asynchronously, with support for code splitting and advanced server side rendering use cases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dynamic require in production

lauterry opened this issue · comments

Hello

My application is server side rendered.
Here is my asyncComponent which load a HomeBackground depending on a marketing code :

export default asyncComponent({
	resolve: () => new Promise(resolve => {
		require.ensure([], () => {
			const path = getStore().getState().marketing.code || "default";
			const component = require("./" + path + "/HomeBackground.jsx");
			resolve(component);
		}, "home-background-loader");
	}),
	serverMode: "resolve"
});

In dev mode, everything works perfectly.

However when I build the app for production, I encounter the following issue (marketing code here is "ul") :

capture d ecran 2017-04-28 a 11 49 43

I wonder if dynamic require is handled by react-async-component ?

What am I doing wrong ?

Best regards

Just a shot in the dark but to the best of my knowledge jsx won't compile in the browser. Perhaps use the webpack resolve property to allow you to import that file without specifying the extension.