jotai-react-refresh-ts-plugin
This plugin adds support for React Refresh for Jotai atoms. This makes sure that state isn't reset, when developing using React Refresh.
Install
npm install jotai-react-refresh-ts-plugin --save-dev
Usage
With a webpack
configuration file:
const { join } = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { createJotaiReactRefreshTransformer } = require('jotai-react-refresh-ts-plugin')
module.exports = {
entry: './tests/fixtures/simple.tsx',
output: {
filename: '[name].[hash].js',
path: join(process.cwd(), 'dist'),
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
},
mode: 'development',
devtool: 'cheap-module-source-map',
module: {
rules: [
{
test: /\.(j|t)sx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
getCustomTransformers: () => ({
before: [
createJotaiReactRefreshTransformer({
customAtomNames: ['myCustomAtom']
}),
],
}),
compilerOptions: {
jsxFactory: 'jsx',
},
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader?minimize'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: join(process.cwd(), 'tests', 'fixtures', 'index.html'),
}),
],
}