Babel ES2015 Object.assign transform config in Laravel Elixir
Asked Answered
E

0

6

I am using knockout.js components where Laravel passes configuration information.

The knockout code lists default options, and merges them with the laravel parameters, using ES2015 (new Javascript) e.g:

this.options = {};
const defaults = {
    option1: true,
    option2: false,
    option3: true
};
Object.assign(this.options,defaults,data.options);

Where data.options are the options set in Laravel Blade

Object.assign works fine except <= IE9

So I have to insert code instead of Object.assign:

for (var key in defaults) {
    if (data.options.hasOwnProperty(key)) {
        this.options[key] = data.options[key];
    } else {
        this.options[key] = defaults[key];
    }
}

I would love to kill this old code but still support IE9 using the following NPM Babel transform:

https://www.npmjs.com/package/babel-plugin-transform-object-assign

However Laravel Elixir appears to not have a babel.rc config, so I am unable to get this transform working.

Help appreciated!

Exposed answered 20/4, 2016 at 10:13 Comment(3)
Would a simple "old fashioned" polyfill help? developer.mozilla.org/en/docs/Web/JavaScript/Reference/… (bottom of page)Befoul
Thanks - I am really trying to get Laravel Elixir to apply the polyfill / transform for me (so I can also apply other transforms later, if needed). But I could add a polyfill to the app.js if all else fails.Exposed
Which version of Laravel Elixir are you using? Can you post the gulpfile.js?Latrell

© 2022 - 2024 — McMap. All rights reserved.