webpack-isomorphic-dev-middleware
webpack-isomorphic-dev-middleware copied to clipboard
Get exported function from server's entry file
Hi!
I have a misunderstanding about how I can export render functions from a server file
I get empty object from res.locals.isomorphic.exports
config for server
const server = {
mode: 'development',
entry:'./src/server.js',
output: {
path: '/',
publicPath: 'http://localhost:3000/scripts/',
filename: `server.bundle.js`,
},
module: {
rules: [js]
},
}
server.js
export const fun =() => console.log('!!!!!!')
export default {
foo: () => {}
}
@ilyaagarkov I've never tried using a default export actually. Could you instead export a render function to see if it's available?
(sorry or the late response)
I ran into the same problem, and after spending a few hours on it I managed to get it works. In my case the problem was that webpack-isomorphic-dev-middleware uses require-from-string to extract exports from the server bundle. However, this only works is the server bundle is generated in a very specific way.
In my case I fixed by adding library and libraryTarget to output.
output: {
...
library: 'library',
libraryTarget: 'commonjs-module',
},
This makes it so that the server bundle has module.exports (instead of being wrapped in webpack helper functions), so that require-from-string can extract the exports.
@arthens Correct, I will leave this open as a reminder to make this clear in the README