Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue-cli 3 打包支持 IE #52

Open
huangshuwei opened this issue Jan 10, 2021 · 0 comments
Open

vue-cli 3 打包支持 IE #52

huangshuwei opened this issue Jan 10, 2021 · 0 comments

Comments

@huangshuwei
Copy link
Owner

huangshuwei commented Jan 10, 2021

前言

很多情况下,我们还是需要支持 IE 的。vue-cli 3 打包支持IE 和 vue-cli 稍有差异。

回顾vue-cli 2 打包支持IE

babel 配置

// babel.config.js
module.exports = {
    presets: [
        ["@vue/app",
            {
                "useBuiltIns": "entry"
            }
        ],
    ]
...
}

修改入口文件
安装 @babel/polyfill

yarn add @babel/polyfill

在入口文件引入

 import '@babel/polyfill'

设置浏览器兼容
根据实际情况设计你的浏览器兼容方案

"browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]

vue-cli 3 打包支持IE

babel 配置

// babel.config.js
module.exports = {
    presets: [
        [
            "@vue/app",
            {
                useBuiltIns: "entry",
                corejs: 3,
                targets: {
                    ie: "11"
                },
                jsx: {
                    injectH: false
                }
            }
        ]
    ]
...
}

修改入口文件
安装 core-jsregenerator-runtime

yarn add core-js regenerator-runtime

在入口文件引入

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

设置浏览器兼容
根据实际情况设计你的浏览器兼容方案

"browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]

transpileDependencies
默认打包时不会检查依赖包,上述的配置只会检查项目本身代码,并做兼容处理。如果发现上述配置还是不支持IE,那么你要排除是否是以来包引起。如highlight.js就是不支持IE 的第三方包,配置如下

// vue.config.js
module.exports = {
  transpileDependencies: ["highlight.js"];
  ...

}

@huangshuwei huangshuwei changed the title vue-cli 3 打包支持 IE11 vue-cli 3 打包支持 IE Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant