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

ie8 怎么兼容? #31

Closed
louisscrew opened this issue Mar 30, 2017 · 14 comments
Closed

ie8 怎么兼容? #31

louisscrew opened this issue Mar 30, 2017 · 14 comments

Comments

@louisscrew
Copy link

我已经在index页面上引入了es5-shim.js

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Omi</title>
    <script src="js/es5-shim.min.js"></script>
    <link rel="stylesheet" href="css/index-ef14a72eca.css">
</head>
<body>

    <script src="js/vendor.9da31384.js"></script>

    <script src="js/omi.27cdf71e.js"></script>

    <script src="js/index.25f7b79d.js"></script>

</body>
</html>

但是在运行的时候还是出现了错误。

错误如下:
网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
时间戳: Thu, 30 Mar 2017 07:39:28 UTC

消息: 对象不支持此操作
行: 1059
字符: 2
代码: 0
URI: file:///D:/screwspace/webfront/omi/test/dist/js/omi.27cdf71e.js

消息: 对象不支持此属性或方法
行: 1
字符: 1
代码: 0
URI: file:///D:/screwspace/webfront/omi/test/dist/js/omi.27cdf71e.js

消息: 缺少标识符、字符串或数字
行: 16
字符: 79
代码: 0
URI: file:///D:/screwspace/webfront/omi/test/dist/js/index.25f7b79d.js

应该还是兼容性的问题。

@dntzhang
Copy link
Collaborator

dntzhang commented Mar 30, 2017

最新的omi-cli v0.2.2引擎默认加上了下面的webpack config和devDependencies配置。

webpack config里加上

  //support ie8
                    plugins : [
                        "transform-es3-property-literals",
                        "transform-es3-member-expression-literals"
                    ]

devDependencies里加入了:

    "babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
    "babel-plugin-transform-es3-property-literals": "^6.22.0",

保险起见引用 es5-sham

<!--[if lt IE 9]>
<script type="text/javascript" crossorigin="anonymous" src="//s.url.cn/qqun/xiaoqu/buluo/p/js/es5-sham-es5-sham.min.77c4325f.js"></script><![endif]-->

@louisscrew
Copy link
Author

louisscrew commented Mar 30, 2017

我已经添加了上面的配置和es5-sham。。。

结果如下
网页错误详细信息

消息: 对象不支持此属性或方法
行: 1
字符: 239
代码: 0
URI: http://localhost:3000/js/es5-sham.js

我在bootstrap上下载的es5-sham,你给我的地址cdn由于公司的限制我链接不上。会和这个有关吗?

@dntzhang
Copy link
Collaborator

重新build下项目

@dntzhang
Copy link
Collaborator

你把我发的cdn另存为

@louisscrew
Copy link
Author

我肯定是重新运行的npm run dist呀

公司的网络禁止这个cdn了。。还没有别的cdn吗?或者给我发个邮件?wen-q@neusoft.com

@dntzhang
Copy link
Collaborator

Npm Run dev试试,看下什么错

@louisscrew
Copy link
Author

用Npm Run dev也一样,在IE8下面也看不出来什么错呀。
就是如下错误

消息: 对象不支持此属性或方法
行: 1
字符: 239
代码: 0
URI: http://localhost:3000/js/es5-sham.js

@dntzhang
Copy link
Collaborator

dntzhang commented Mar 31, 2017

怎么会看不出来什么错啊 = =! 你全部都不要用压缩版的js就能看出来什么错了~~ 你这个看上去是你的es5-sham.js不兼容ie8. 而不是omi的问题

@louisscrew
Copy link
Author

我的天。。IE8呀。老兄。我还真不知道用什么能查看到错误。

首先第一个错误点就是es5-sham.js报出来的,提示对象不支持此属性或方法,下一个错误就是
vendor.js报出来的。定位的是
Object.defineProperty方法不支持。

所以错误很明显,es5-sham根本没有起作用。

@dntzhang
Copy link
Collaborator

是的,所以说这个看上去是你的es5-sham.js不兼容ie8. 压根就没起作用

@dntzhang
Copy link
Collaborator

@louisscrew
Copy link
Author

louisscrew commented Mar 31, 2017

好使了。
我在es5-shim 的github上下载到未压缩的源码。

之后放到了js目录。

并且在webpack上把两个源码压缩到了vendor.js里面。运行就成功了。不止需要sham还需要shim

我的配置如下:
config.entry.vendor = [
'./src/js/es5-shim.js'
,'./src/js/es5-sham.js'
,'omi'
,'./src/common/class_list.js'
];
config.output.filename = '[name].js';
config.plugins[1] = new commonChunkPlugin({
name:"vendor",
filename:"vendor.js"
})

这样在IE8下就正常的运行。 谢谢。

@MagicLeeW
Copy link

@louisscrew 谢谢兄弟,你的回答解决了我的大问题

@Muna-Lombe
Copy link

Muna-Lombe commented Mar 2, 2022 via email

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

4 participants