swc-project / swc-loader

Moved to https://github.com/swc-project/pkgs
MIT License
394 stars 29 forks source link

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

Open ghost opened 2 years ago

ghost commented 2 years ago

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.

alexgwolff commented 2 years ago

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),
    },
  },
},
busy-mango commented 1 year ago

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