SSR compatible project
Background
I'm trying to build some isomorphic apps which could run in worker/server/browser
. But in most cases, I couldn't start my application smoothly in worker/server
sides, some dependencies of my application use the window/document
objects directly event their code path will never be reached.
In these case, I want wrap a simple adapter around these libraries, for example:
if (typeof window !== 'undefined') {
// raw javascript content
}
So with ssr-compatible-loader
, we could handle some amd/cjs
format libraries in this simple way.
// webpack.config.js
export default {
module: {
rules: [
{
use: 'ssr-compatible-loader',
include: [/node_modules[\\/](wavesurfer\.js|some\-other\-libraries)[\\/]/],
},
]
}
}