鍍金池/ 問(wèn)答/網(wǎng)絡(luò)安全  HTML/ 為什么 Vue 的 webpack 模板不使用 polyfill 也能在 IE

為什么 Vue 的 webpack 模板不使用 polyfill 也能在 IE 瀏覽器上使用 assign 等 ES6+ 方法

  1. 為什么 Vue 的 Webpack 模板不使用 polyfill 也能在 IE 瀏覽器上使用 Object.assign 等 ES6+ 方法。而且在模板的package.json和相關(guān)配置沒(méi)有看到babel-polyfill
  2. babel-loader 不能根據(jù)我的代碼中ES6使用情況自動(dòng)添加相關(guān)的polyfill嗎?感覺(jué)使用我的配置是根據(jù)browserlist 添加的polyfill
  3. 當(dāng)我自己使用 Webpack4 的時(shí)候,如果需要使 IE 瀏覽器上能正確使用 ES6+ 方法。需要在入口文件添加一行import 'babel-polyfill'

附上我的webpack配置:

'use strict';
const path = require('path');
module.exports = {
  mode: 'development',
  entry: {
    index: path.join(__dirname, './index.js'),
  },
  output: {
    filename: '[name].bundle.js',
  },
  devtool: 'cheap-module-eval-source-map',
  devServer: {
    contentBase: path.resolve(__dirname, './'),
    port: 8000,
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            cacheDirectory: true,
            presets: [[ 'env', {
              useBuiltIns: true,
            }]],
            plugins: [ 'transform-runtime' ],
          },
        },
      },
    ],
  },
};

回答
編輯回答
柚稚
  1. Object.assign 不需要 babel-polyfill
  2. babel 是可以做到。 但問(wèn)題是, 你是否需要轉(zhuǎn)化呢? 如果你的目標(biāo)瀏覽器就是最新瀏覽器就好了,它是不是就沒(méi)有必要轉(zhuǎn)化了?
2017年9月4日 10:01
編輯回答
野橘

babel 只轉(zhuǎn)語(yǔ)法 ,不轉(zhuǎn)api,新的api需要引入babel-polyfill

2017年5月26日 10:14