ssr-polyfill
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

ssr-polyfill 👋

Version Documentation Maintenance License: ISC

fake browser runtime environment in server-side render.

🏠 Homepage

Install

npm install ssr-polyfill --save
# or yarn add ssr-polyfill 

Usage

in node env:

const ssrPolyfill = require('ssr-polyfill');
global.window = ssrPolyfill({
  context: {
    userInfo: 'hello',
  }
});
global.self = global.window;
// maybe you can mock somewhere
// not use `window.document` use `document.*`
global.document = global.window.document;
// in client env `window.context` is { userInfo: 'hello' }
  • url default is http://localhost, you also change the location.pathname use http://localhost/bar
  • html init html template, default is <body><div id="root"></div></body>
  • other params will mount in window object

Run tests

npm run test

Author

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

This project is ISC licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i ssr-polyfill

Weekly Downloads

113

Version

1.0.1

License

ISC

Unpacked Size

9.6 kB

Total Files

12

Last publish

Collaborators

  • ycjcl868