简体   繁体   中英

nuxtjs issue with IE11 compatibility_ object assign

I am suffered by IE compatibility. (my vue version is 3.1.0, nuxt is 2.3.4)

It keeps error with Object.assign . Here is the list what I have tried.

  • babel-preset-vue-app( https://www.npmjs.com/package/babel-preset-vue-app ). Heard that it does not support vue2.X. I followed the description on this post . It gets an error while building source.

  • Adding babel-polyfill in nuxt.config.js . It does not error, but still I got Object.assign error on the page.

  • Install babel/plugin-transform-object-assign . It also does not make any error in build process, but got Object assign thing in the page.

Is there any option I can try to feet IE11 compatibility?

Here is my current .babelrc and nuxt.config.js .

.babelrc

{
    "presets": [
        [
            "env",
            {
                "modules": false
            }
        ],
        [ "vue-app",
            {
                "useBuiltIns": true,
                "targets": {
                    "ie": 9,
                    "uglify": true
                }
            }
        ]
    ],
    "plugins": [
        "@babel/plugin-transform-object-assign",
        "transform-vue-jsx",
        [
            "module-resolver",
            {
                "root": [
                    "./src"
                ],
                "alias": {
                    "~sbdc": "./src/sbdc"
                }
            }
        ]
    ]
}

build option in nuxt.config.js

build: {
    babel: {
        presets: [
            ['vue-app', {
                useBuiltIns: true,
                targets: { ie: 9, uglify: true }
            }
            ]
        ]
    },
    optimization: {
        splitChunks: {
            chunks: 'all',                  
            maxInitialRequests: Infinity,       
            minSize: 0,                     
            cacheGroups: {              
              vendor: {
                  test: /[\\/]node_modules[\\/](babel-polyfill|moment|lodash|axios|get-size|jquery|js-cookie|jwt-decode|numeral|vuetify)[\\/]/,
                  name: 'utilityVendor'
                }
            }
        }
    },
    output: {
        publicPath: serviceConfig.pwa_publicPath || false
    },
    extractCSS: true,
    plugins: [
        new webpack.ProvidePlugin( {
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
        } )
    ]
}

Thanks for sharing you solutions!

======= Edited in 0114 =============

Etra information #1. When I look at the error on ie11 browser, it automatically transform code like below

return {layout:"popup",data:[{resultBody:Object.assign(Object.create(null), ... sorry, sensitive data

while the original code is...

asyncData: async function ({req}) {
    return {
        resultBody: req.body,
    };
},

req.body is supported by body-parser .

After hours of struggling, I solved this with not good way(In my thought).

I just add object-assign polyfill js to nuxt.js

module.exports = {

    ...

    head: {
        script: [ { src: '/js/object-assign.js' } ]
    },

    ... 

};

But I still want to know the proper way to apply babel-polyfill into nuxt project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM