Skip to content

Commit

Permalink
feat: Add “use client” to fix React Server Components (#2656)
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh authored Nov 21, 2023
1 parent cc8ae36 commit fad63b1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const { BannerPlugin } = require('webpack')

const uswdsIncludePaths = [
'./node_modules/@uswds',
Expand All @@ -19,6 +21,18 @@ module.exports = {
libraryTarget: 'umd',
globalObject: 'this',
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// Preserve directives like "use client"
directives: false,
},
},
}),
],
},
externals: {
react: {
root: 'React',
Expand All @@ -39,6 +53,14 @@ module.exports = {
chunkFilename: '[name].[id].css',
}),
new ForkTsCheckerWebpackPlugin(),
new BannerPlugin({
// Support React Server Components
// See: https://react.dev/reference/react/use-client
banner: '"use client";',
raw: true,
entryOnly: true,
test: /\.js$/,
}),
],
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
Expand Down

0 comments on commit fad63b1

Please sign in to comment.