Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

swc-loader seems to ignore .browserslistrc #37

Open
yoav-lavi opened this issue Jan 28, 2022 · 5 comments
Open

swc-loader seems to ignore .browserslistrc #37

yoav-lavi opened this issue Jan 28, 2022 · 5 comments

Comments

@yoav-lavi
Copy link

yoav-lavi commented Jan 28, 2022

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!

@ghost
Copy link

ghost commented Aug 11, 2022

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.

@SukkaW
Copy link

SukkaW commented Sep 1, 2022

@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.

@ghost
Copy link

ghost commented Sep 1, 2022

@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,
...

@awdr74100
Copy link

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

@kdy1
Copy link
Member

kdy1 commented Sep 21, 2022

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

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

No branches or pull requests

4 participants