Brooooooklyn / ssr-compatible

Wrap SSR adapter for non-compatible libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)[\\/]/],
      },
    ]
  }
}

About

Wrap SSR adapter for non-compatible libraries


Languages

Language:TypeScript 66.4%Language:JavaScript 24.9%Language:HTML 8.7%