Vue2+Webpack+ES6 兼容低版本浏览器(IE)

1.安装 “babel-polyfill”

1.1命令:npm install --save-dev babel-polyfill

1.2在入口main.js文件引入:import ‘babel-polyfill’

1.3在build文件夹下找到webpack.base.conf.js.修改入口方式:

 entry: {

​   app: ["babel-polyfill", "./src/main.js"]

 }

2.依赖一个插件解决ES6/ES7高级语法兼容

2.1 npm install --save-dev babel-preset-es2015-ie

2.2 如果根目录下缺少文件.babelrc,新建一个,如下:

{
   "presets": [
          ["env", {
               "modules": false,
                "targets": {
                      "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
                     }
          }],
         "stage-2"
   ],
  "plugins": ["transform-runtime"],
  "env": {
    "test": {
       "presets": ["env", "stage-2"],
       "plugins": ["istanbul"]
     }
   }
}

你可能感兴趣的:(webpack,es6,javascript)