-
-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Labels
enhancementp2Medium: enhancements, docs, quality improvementsMedium: enhancements, docs, quality improvements
Description
Summary
Shakapacker 9.1+ supports both Webpack and Rspack bundlers, but users must write custom utility code to handle bundler-specific imports (e.g., CSS extraction plugins).
The Problem
When switching between bundlers, code like this breaks:
// Breaks when switching to Rspack
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// Need conditional logic:
const isRspack = config.assets_bundler === 'rspack';
const CssPlugin = isRspack
? require('@rspack/core').CssExtractRspackPlugin
: require('mini-css-extract-plugin');Current Workaround
Projects create their own utility modules:
// config/webpack/bundlerUtils.js
const { config } = require('shakapacker');
const getBundler = () => {
return config.assets_bundler === 'rspack'
? require('@rspack/core')
: require('webpack');
};
const getCssExtractPlugin = () => {
return config.assets_bundler === 'rspack'
? require('@rspack/core').CssExtractRspackPlugin
: require('mini-css-extract-plugin');
};
module.exports = { getBundler, getCssExtractPlugin };Proposal
Export bundler utilities from shakapacker:
const {
getBundler, // Returns webpack or @rspack/core
isRspack, // Boolean check
getCssExtractPlugin, // Returns appropriate CSS plugin
getDefinePlugin, // webpack.DefinePlugin or rspack.DefinePlugin
} = require('shakapacker');This would make bundler switching seamless for common use cases.
Environment
- Shakapacker 9.5.0
- Projects using both Webpack and Rspack
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementp2Medium: enhancements, docs, quality improvementsMedium: enhancements, docs, quality improvements