IE瀏覽器error:Promise未定義

原因:ie對es6的支持很糟.不認識Promise、箭頭函數等等。。
解決方法
安裝babel-polyfill插件

yarn add babel-polyfill

npm install --save babel-polyfill

引入:

//在common.js(全局公共js)中引入即可
import "babel-polyfill"

如果不行,這些也裝一下:
babel-loader、babel-core、babel-preset-env
同時:

var path = require('path');
 module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
    //在webpack.config.js中配置一下
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }
      }
    ]
  }
};

參考:
IE瀏覽器error:Promise未定義
webpack 配置es6語法轉義es5語法方法

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章