美文网首页
Vue-cli3以上版本添加IE兼容

Vue-cli3以上版本添加IE兼容

作者: 紫月凌枫 | 来源:发表于2023-01-11 21:22 被阅读0次

    安装babel相关依赖做js转换处理
    package.json

    {
      ...
      "dependencies": {
        "@vue/cli-plugin-babel": "~4.4.0",
        "core-js": "^3.15.2",
        "regenerator-runtime": "^0.13.7",
      }
      ...
      "browserslist": [
        "> 1%",
        "last 2 versions",
        "not ie <= 9"
      ]
    }
    

    配置babel
    babel.config.js

    module.exports = {
      presets: [
        ['@vue/app', {
          useBuiltIns: 'entry'
        }]
      ],
      plugins: [
        [
          'component',
          {
            libraryName: 'element-ui',
            styleLibraryName: 'theme-chalk'
          }
        ]
      ]
    };
    

    由于babel默认不处理node-modules里面的文件,故需要将要处理的依赖手动添加到需要处理的列表中
    vue.config.js

    module.exports = {
      transpileDependencies: ['element-ui']
    }
    

    入口文件处添加babel
    main.js

    import 'core-js/stable';
    import 'regenerator-runtime/runtime';
    

    参考文档:
    vue-cli文档之浏览器兼容性

    相关文章

      网友评论

          本文标题:Vue-cli3以上版本添加IE兼容

          本文链接:https://www.haomeiwen.com/subject/yinvpltx.html