Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

vue项目IOS9项目白屏!vue报错::ES6转码ES5失败,

线上vue项目在其他手机开打一切正常,但是在ios9.3报错:SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode!

查了一些资料说是因为ios9.3不支持es6语法

一顿操作猛如虎,一看操作还是失败

1)webpack-dev-server回滚到了2.7.1

2)安装了babel-preset-es2015 babel-preset-es2015

main.js也引入了import 'babel-polyfill'和import 'es6-promise/auto'

但是打包之后在dist文件夹下所搜还是能查到const和let,项目在ios9.3还是报错!!说明es6没有成功转成es5!!

请问各位大神有什么办法?

网上找了很多种方法都失败!!!

这个问题搞了我两天了!!!

为什么es6转es5失败?
babelrc文件.pngconfig下的indexjs文件.pngmain文件.pngpackage文件.pngwebpack.base.conf文件.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

我也遇到过类似的问题,但是忘了怎么解决的了,说下我现在的配置:

//  package.json
{
//  ... 其他配置不列出来了
  "browserslist": [
    "defaults",
    "not ie < 11",
    "last 2 versions",
    "> 1%",
    "iOS 7",
    "last 3 iOS versions"
  ],
  "babel": {
    "presets": [
      "env"
    ],
    "plugins": [
      [
        "transform-runtime"
      ]
    ]
  }
}

// webpack.common.js
// 一条 rule
    {
        test: /.js$/i,
        exclude: /(node_modules|brower_components)/,
        loader: 'babel-loader'
    }

我没有写 .babelrc,根据官网的说法,在 package.json 里写也是等价的。
最大的嫌疑是 browsersList


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...