question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to modify babel-preset-env configuration?

See original GitHub issue
  • Laravel Mix Version: 1.4.2
  • Node Version (node -v): v8.4.0
  • NPM Version (npm -v): 5.3.0
  • OS: Mac

Description:

In src/config.js there is:

        babel: function () {
            let options = {};

            tap(Mix.paths.root('.babelrc'), babelrc => {
                if (File.exists(babelrc)) {
                    options = JSON.parse(File.find(babelrc).read());
                }
            });

            let defaultOptions = {
                cacheDirectory: true,
                presets: [
                    ['env', {
                        'modules': false,
                        'targets': {
                            'browsers': ['> 2%'],
                            uglify: true
                        }
                    }]
                ]
            };

            if (this.react) {
                defaultOptions.presets.push('react');
            }

            return webpackMerge.smart(defaultOptions, options);
        },

Steps To Reproduce:

In my .babelrc I have

{
  "presets": [
    ["env", {
        "targets": {
            "browsers": ["> 5%"],
            "uglify": false
        }
    }]
  ]
}

However, this is just concatenating this as another ‘env’ preset and it isn’t being used. How can I modify the original env preset?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
darrena092commented, Oct 15, 2018

This essentially makes Laravel Mix no longer useful for my case as it seems to not be transpiling for IE11 now which clients are still requesting support for. IMO this feature should be pretty high priority - there will always be edge cases where the > 2% target is not appropriate.

2reactions
atomitacommented, Dec 19, 2017

Example of update the merge strategy.

let _ = require('lodash'),
    webpackMerge = require('webpack-merge'),
    smart = webpackMerge.smart;

webpackMerge.smart = function(a, b) {
    var r = smart.call(webpackMerge, a, b);

    if (! b.presets) {
        return r;
    }

    let i = _.findIndex(b.presets, [0, 'env']);
    if (i < 0) {
        return r;
    }

    let j = _.findIndex(r.presets, [0, 'env']);
    if (j < 0) {
        j = r.presets.length;
        r.presets.push(['env']);
    }

    r.presets[j][1] = _.defaults({}, b.presets[i][1] || {}, r.presets[j][1] || {});

    return r;
};

let mix = require('laravel-mix');

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');
Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/preset-env
This option configures how @babel/preset-env handles polyfills. When either the usage or entry options are used, @babel/preset-env will add direct references ...
Read more >
Presets - Babel.js
Babel presets can act as sharable set of Babel plugins and/or config options . Official Presets. We've assembled a few presets for common...
Read more >
Configure Babel
Create a file called babel.config.json with the following content at the root of your project (where the package.json is). ... Check out the...
Read more >
babel-preset-es2015 -> babel-preset-env - Babel.js
Babel 7. If you are using Babel version 7 you will need to run npm install @babel/preset-env and have "presets": ["@babel/preset-env"] in your...
Read more >
Config Files - Babel.js
Babel can be configured using any file extension natively supported by Node.js, as mentioned in Configuration File Types section: babel.config.json and .babelrc ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found