Nuxt.js: @nuxt/babel-preset-app ignores .browserlistrc

Created on 13 Feb 2019  路  4Comments  路  Source: nuxt/nuxt.js

Version

v2.4.3

Reproduction link

https://codesandbox.io/s/qqwx3175kq

Steps to reproduce

create file .browserslistrc with valid browserlist query, say ie 11

in nuxt.config.js enable babel debug mode

      presets: ({ isServer }) => [
        [
          '@nuxt/babel-preset-app',
          {
            debug: true,
          },
        ],
      ],

to observe babel config

What is expected ?

babel runs with target "ie 11"

What is actually happening?

babel run with default config "ie 9"

Additional comments?

https://github.com/nuxt/nuxt.js/blob/dev/packages/babel-preset-app/src/index.js#L53
probably due to "ie 9" would be used when target is not defined, despite browserlist exists

This bug report is available on Nuxt community (#c8653)
bug-report pending

Most helpful comment

@williamchong007
Since nuxt will set ie9(client) and node: current(server) as default targets, so if you want to use browserlist, please try this for enabling browserslist in client building:

Note: .browserslistrc under configPath (starting point of searching)

  build: {
    babel: {
      presets: ({ isServer }) => {
        return [[
          '@nuxt/babel-preset-app',
          {
            buildTarget: isServer ? 'server' : 'client', // for auto import polyfill
            targets: isServer ? { node: 'current' } : {},
            configPath: __dirname // if cwd is same as dir of .browserslistrc, no need to specify
          }
        ]]
      }
    }
  }

All 4 comments

Not sure whether it's intended to respect the a .browserlistrc or not.
馃

cc @clarkdo

@williamchong007
Since nuxt will set ie9(client) and node: current(server) as default targets, so if you want to use browserlist, please try this for enabling browserslist in client building:

Note: .browserslistrc under configPath (starting point of searching)

  build: {
    babel: {
      presets: ({ isServer }) => {
        return [[
          '@nuxt/babel-preset-app',
          {
            buildTarget: isServer ? 'server' : 'client', // for auto import polyfill
            targets: isServer ? { node: 'current' } : {},
            configPath: __dirname // if cwd is same as dir of .browserslistrc, no need to specify
          }
        ]]
      }
    }
  }

Thanks for the reply
Should I treat this as a temp fix or a long term solution?

@williamchong007

Now, You can use it for sure, and I'll just close this issue 馃槃

About some more appropriate solution, I'll think about it, if you have any suggestions, feel free to comment here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

surmon-china picture surmon-china  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

maicong picture maicong  路  3Comments

msudgh picture msudgh  路  3Comments

VincentLoy picture VincentLoy  路  3Comments