Skip to content

Commit 4c761bb

Browse files
justin808claude
andcommitted
Add bundler auto-detection to all webpack config files
Updated client.js, server.js, and clientWebpackConfig.js to use bundler auto-detection instead of hardcoded webpack requires. This ensures ProvidePlugin and DefinePlugin use the correct bundler (webpack or @rspack/core) based on shakapacker config. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 752919b commit 4c761bb

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

config/webpack/client.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
const devBuild = process.env.NODE_ENV === 'development';
22
const isHMR = process.env.WEBPACK_DEV_SERVER === 'TRUE';
33
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
4-
const webpack = require('webpack');
4+
const { config } = require('shakapacker');
55
const environment = require('./environment');
66

7+
// Auto-detect bundler from shakapacker config and load the appropriate library
8+
const bundler = config.assets_bundler === 'rspack'
9+
? require('@rspack/core')
10+
: require('webpack');
11+
712
if (devBuild && !isHMR) {
813
environment.loaders.get('sass').use.find((item) => item.loader === 'sass-loader').options.sourceMap = false;
914
}
1015

1116
environment.plugins.append(
1217
'Provide',
13-
new webpack.ProvidePlugin({
18+
new bundler.ProvidePlugin({
1419
$: 'jquery',
1520
jQuery: 'jquery',
1621
jquery: 'jquery',

config/webpack/clientWebpackConfig.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// The source code including full typescript support is available at:
22
// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/clientWebpackConfig.js
33

4-
const webpack = require('webpack');
4+
const { config } = require('shakapacker');
55
const commonWebpackConfig = require('./commonWebpackConfig');
66

7+
// Auto-detect bundler from shakapacker config and load the appropriate library
8+
const bundler = config.assets_bundler === 'rspack'
9+
? require('@rspack/core')
10+
: require('webpack');
11+
712
const configureClient = () => {
813
const clientConfig = commonWebpackConfig();
914

1015
clientConfig.plugins.push(
11-
new webpack.ProvidePlugin({
16+
new bundler.ProvidePlugin({
1217
$: 'jquery',
1318
jQuery: 'jquery',
1419
ActionCable: '@rails/actioncable',

config/webpack/server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
const merge = require('webpack-merge');
22

33
const devBuild = process.env.NODE_ENV === 'production' ? 'production' : 'development';
4-
const webpack = require('webpack');
5-
4+
const { config } = require('shakapacker');
65
const environment = require('./environment');
76

7+
// Auto-detect bundler from shakapacker config and load the appropriate library
8+
const bundler = config.assets_bundler === 'rspack'
9+
? require('@rspack/core')
10+
: require('webpack');
11+
812
// React Server Side Rendering shakapacker config
913
// Builds a Node compatible file that React on Rails can load, never served to the client.
1014

1115
environment.plugins.insert(
1216
'DefinePlugin',
13-
new webpack.DefinePlugin({
17+
new bundler.DefinePlugin({
1418
TRACE_TURBOLINKS: true,
1519
'process.env': {
1620
NODE_ENV: devBuild,

0 commit comments

Comments
 (0)