scottcharlesworth / laravel-mix-polyfill

A Laravel Mix extension to include polyfills by using Babel, core-js, and regenerator-runtime
MIT License
50 stars 7 forks source link

.browserlistrc not being picked up #34

Closed markhalliwell closed 3 years ago

markhalliwell commented 3 years ago

According to the following documentation, setting the targets options to false should automatically allow .browserslistrc to be picked up; however, that isn't the case.

Setting to false will also allow use of browserslist config sources (like .browserslistrc). See here and here for more information.

Installed versions:

.browserslistrc:

[modern]
last 1 chrome version
last 1 firefox version

[production]
last 1 versions
> 1%
not dead

Command being executed:

mix --production && cross-env BROWSERSLIST_ENV=modern mix --production

The only way I'm able to get it to work is if I do the following to manually set the targets:

const { BROWSERSLIST_ENV, NODE_ENV } = process.env
const browserslistEnv = BROWSERSLIST_ENV || NODE_ENV
const browsersListConfig = readConfig(path.resolve(__dirname, `.browserslistrc`))
const browsersList = browsersListConfig[browserslistEnv] || browsersListConfig.defaults || []

mix.polyfill({
  targets: browsersList.join(', '),
})

My guess is that it might have something to do with the cacheDirectory only being set if debug is enabled.

scottcharlesworth commented 3 years ago

@markhalliwell I've just tested this and it works as expected. The .browserslistrc is being detected and the correct category/query is being read.

What appears to be happening is the BROWSERSLIST_ENV value is being ignored in favour of the NODE_ENV set by Laravel Mix when running with --production.