Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]align rspack plugin with webpack plugin #377

Open
maroon1 opened this issue Feb 22, 2024 · 1 comment
Open

[Feature Request]align rspack plugin with webpack plugin #377

maroon1 opened this issue Feb 22, 2024 · 1 comment

Comments

@maroon1
Copy link

maroon1 commented Feb 22, 2024

There are many rspack config that is compatible with webpack, it's great if rspack plugin align with webpack plugin.

I find that rspack plugin use cssModules option to determine how css module work, but webpack plugin define two loader rules to sperately handle global css and css module. It result hard to migrate to rspack from webpack

in rspack plugin

{
test: /\.css$/,
type: opts?.cssModules ? 'css/module' : undefined,
},
{
test: /\.scss$|\.sass$/,
type: opts?.cssModules ? 'css/module' : undefined,
use: [
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: !!options.sourceMap,
sassOptions: {
fiber: false,
// bootstrap-sass requires a minimum precision of 8
precision: 8,
includePaths,
},
},
},
],
},
{
test: /.less$/,
type: opts?.cssModules ? 'css/module' : undefined,
use: [
{
loader: require.resolve('less-loader'),
options: {
sourceMap: !!options.sourceMap,
lessOptions: {
javascriptEnabled: true,
...lessPathOptions,
},
},
},
],
},
{
test: /\.styl$/,
use: [
{
loader: require.resolve('stylus-loader'),
options: {
sourceMap: !!options.sourceMap,
stylusOptions: {
include: includePaths,
},
},
},
],
},

in webpack plugin

https://github.com/nrwl/nx/blob/a1d8645ac57864ba1a7347b9f288f3052aba2263/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-web-config.ts#L128-L243

@phal0r
Copy link

phal0r commented Feb 28, 2024

I agree. This logic is flawed and i could be really easy, because rspack handles css out of the box and it is not even necessary to specify it (https://www.rspack.dev/guide/migrate-from-webpack.html#removing-css-loader-style-loader-and-mini-css-extract-plugin).

Even if it is specified, setting to undefined didn't work in my tests, but you can just set the type to 'css/auto' and rspack will handle style files without ".module" in the name as normal css and files with ".module" in the name as css modules (https://www.rspack.dev/guide/language-support.html#css).

The situation gets worse, when you use withReact instead of withWeb, because withReact loads withWeb internally and forces cssModules, no matter what you pass in as options ->

config = withWeb({ ...opts, cssModules: true })(config, {

All of this should be fixed and configurable, so we don't need to crawl deep into the sourcecode to understand, why the bundling behaves weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants