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

`swc-loader` seems to ignore `.browserslistrc`

Open yoav-lavi opened this issue 3 years ago • 5 comments

Installed Versions

{
  "@swc/core": "^1.2.133",
  "@swc/jest": "^0.2.17",
  "swc-loader": "^0.1.15"
}

The output of swc-loader is different between these two configurations:

webpack.config.ts (partial)

{
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        use: [ isProduction ? 'babel-loader' : 'swc-loader'],
        exclude
      },
    ]
  }
}

.browserslistrc

query1
query2

webpack.config.ts (partial)

{
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        use: [
          isProduction
            ? 'babel-loader'
            : {
                loader: 'swc-loader',
                options: {
                  // swc-loader doesn't seem to automatically detect .browserslistrc
                  env: {
                    targets: 'query1, query2'
                  },
                },
              },
        ],
        exclude,
      },
    ]
  }
}

Option 1 results in es2015 output whereas option 2 uses the browserslist query correctly and results in the expected output.

As a side question, would @swc/jest also have the same issue?

Thanks!

yoav-lavi avatar Jan 28 '22 11:01 yoav-lavi

Is your webpack file not at root level? I'm having the same issue when my configuration is in a subfolder even when using the path property.

ghost avatar Aug 11 '22 10:08 ghost

@vgurkov I am having the same issue even if I put webpack.config.js at the root level, right next to the .browserslistrc and pacakge.json.

SukkaW avatar Sep 01 '22 06:09 SukkaW

@SukkaW All my other loaders can pick up package.json so I'd love it if one of the devs checks this issue out but in the meantime we can pass the browser targets to the loader like

const packageJson = require('../package.json');
...
loader: 'swc-loader',
options: {
...
 env: {
        targets: packageJson.browserslist,
...

ghost avatar Sep 01 '22 06:09 ghost

Is the target option provided by the .browserslistrc file still not supported? It seems that it can only be provided manually?

awdr74100 avatar Sep 20 '22 20:09 awdr74100

Why do you need to left a comment? Issue is not closed

kdy1 avatar Sep 21 '22 00:09 kdy1