swc-loader icon indicating copy to clipboard operation
swc-loader copied to clipboard

Swc-loader seems to ignore .swcrc.json and/or there's no way to specify a config

Open ghost opened this issue 2 years ago • 2 comments

When I normally use SWC I call my config .swcrc.json to keep it consistent with tons of other similar configs and so that my IDE can automatically style the JSON, not being able to use .json is a pain.

When normally running swc I use --config-file .swcrc.json to specify the config, which works fine on most projects. However when using it with swc-loader and webpack, it seems that the config is completely ignored and instead defaults are used. However when calling it ".swcrc" only it seems to work, but I want it to be .json otherwise editing it in IDE looks ugly.

I also don't want to have to duplicate all the configuration to webpack, it's already in .swcrc.json, there shouldn't be any reason to duplicate it in there. Instead swc-loader should be able to read the existing config.

It would be nice if I could use swc-loader and keep my config named what I want it to be named.

ghost avatar Jul 02 '22 20:07 ghost

Hi, you can do this:

const swcrc = await fs.readFile('swcrcPath', 'utf-8');

...


{
  test: /.(t|j)sx?/,
  exclude: /(node_modules)/,
  use: {
    loader: 'swc-loader',
    options: {
      ...JSON.parse(swcrc),
    },
  },
},

alexgwolff avatar Jul 20 '22 04:07 alexgwolff

I agree with swc-loader should be able to read the existing config, plz add this feature.

busy-mango avatar May 01 '23 04:05 busy-mango