Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remorses/next-superjson
Automatically transform your Next.js Pages to use SuperJSON, without losing swc support
https://github.com/remorses/next-superjson
nextjs superjson
Last synced: 19 days ago
JSON representation
Automatically transform your Next.js Pages to use SuperJSON, without losing swc support
- Host: GitHub
- URL: https://github.com/remorses/next-superjson
- Owner: remorses
- Created: 2021-10-27T09:48:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T10:09:19.000Z (10 months ago)
- Last Synced: 2024-05-02T02:10:44.330Z (9 months ago)
- Topics: nextjs, superjson
- Language: TypeScript
- Homepage:
- Size: 235 KB
- Stars: 70
- Watchers: 4
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- Awesome-NextJs - next-superjson
README
## Getting started
Install the library with your package manager of choice, e.g.:
```
npm install next-superjson next-superjson-plugin superjson
```Since this is a companion to [SuperJSON](https://github.com/blitz-js/superjson),
make sure it's also installed, also with `next-superjson-plugin` which is a runtime dependency.Add the plugin to your `next.config.js`.
If you don't have one, create it.```js
const { withSuperjson } = require('next-superjson')module.exports = withSuperjson()({})
```> [!NOTE]
> Notice that you have to call the plugin function 2 times, this is to support options in the futureThat's it! Now you're free to use all values and type supported by SuperJSON in your Next.js Components.
# How it works
New Nextjs 12 uses `swc` to compile user code by default, adding a custom `.babelrc` file will make Nextjs compile everything using Babel instead (much slower).
This plugin will inject the superjson plugin only on files under the `pages` directory so you can keep using swc for all the other files.
Version 1 of this plugin will use the SWC superjson plugin instead of the Babel plugin, this is because the previous Babel plugin no longer works, [thanks to commonjs and ESM skill issues by one of the core developers.](https://github.com/blitz-js/babel-plugin-superjson-next/issues/145#issuecomment-2452145624)
## Turbopack support
Since version 1 this plugin also supports the `--turbo` flag.
## What is the different between this plugin and `next-superjson-plugin` SWC plugin?
`next-superjson-plugin` broke in version 15 of Next.js because SWC was updated to a version that no longer supported plugins built with a different version of `swc_core` binary.
This plugin instead freezes the version of `@swc/core` to one that is guaranteed to work.
## Sponsors
[**Notaku**](https://notaku.website)
[![Notaku](https://preview.notaku.website/github_banner.jpg)](https://notaku.website)