mightyplow a1702d88f4 add README content | 5 lat temu | |
---|---|---|
loadable-mock | 5 lat temu | |
transform-dynamic-import-loader | 5 lat temu | |
.gitignore | 5 lat temu | |
README.md | 5 lat temu | |
index.js | 5 lat temu | |
package-lock.json | 5 lat temu | |
package.json | 5 lat temu |
This is a helper library to enable server side rendering when using @loadable/component for React and building with webpack.
This package contains two helpers:
I successfully tested this with babel-loader and ts-loader.
npm i @mightyplow/loadable-ssr -D
Add these changes in the webpack config for your server application:
module.exports = {
...
// You probably have externals defined to prevent webpack from building node_modules into
// your server application. Mostly webpack-node-externals is being used for this. You have
// to whitelist @loadable/component because otherwise the alias below won't work.
externals: [
require('webpack-node-externals')({
whitelist: [
'@loadable/component'
]
})
],
...
resolve: {
alias: {
// replace @loadable/component with the mock
'@loadable/component': '@mightyplow/loadable-ssr/loadable-mock
}
},
...
module: {
rules: [
{
test: /\.jsx?/,
loaders: [
'babel-loader',
// should be the last item in order to be executed first
'@mightyplow/loadable-ssr/transform-dynamic-import-loader'
]
}
]
}
...
}