2
votes

I started a project using the vue-cli webpack (simple) template.

When I try to build for release using npm run build I get my dist folder with the expected build.js, etc. and when testing the build version the app works in all browsers except IE (11).

The error in IE referenced a Promise so I looked in the dist.js file and saw the new Promise() syntax. I am not very familiar with vue-loader and babel but I thought all the es6+ code would be transpiled to es5 when I run the build command.

I have not modified the webpack.config.js from what is default with the vue-cli webpack template.

Is my expectation wrong about transpilation or am I missing something?

.babelrc

{
  "presets": [
    ["env", { "modules": false }],
    "stage-3"
  ]
}

webpack.config.js

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

node - 6.9.2 | npm - 3.10.2 | vue - 2.9.2

Update 1/3/18

Following the babel-polyfill answer and some more searching I was able to get this working for the production build (npm run build) by changing my 'entry' prop in the webpack.config.js file to

entry: ['babel-polyfill', './src/main.js']

and adding the babel-polyfill import statement to my main.js

import 'babel-polyfill'

after adding babel-loader and babel-polyfill npm packages to my dependencies

1

1 Answers

3
votes

ES6 to ES5 transpilation only handles syntax transformation, not polyfills (these are more like runtime features).

You can either use babel-polyfill (which includes all ES6 related polyfills) or just es6-promise.