Greg Gum
Greg Gum

Reputation: 37909

How to include an ES6 Promise when using the Aurelia-Webpack plugin?

I am using Aurelia 1.1 with the Webpack 2.0 plugin. This works fine in Chrome, but in IE, there is no promise.

So I get an error message on this:

var startPromise = new Promise(function (resolve) {
  return startResolve = resolve;
});

I have downloaded the es6 polyfill with npm, but I don't know how to tell webpack to include it so it can be used universally.

How should I be including this polyfill?

Upvotes: 0

Views: 736

Answers (2)

Estus Flask
Estus Flask

Reputation: 222474

The usual thing for ES6 apps is to have polyfills included (e.g. core-js). This should be done once per app, as early as possible, before other libraries:

import 'core-js/es6';

Considering that aurelia-polyfills is already used, polyfills can be included selectively to not collide with the ones from aurelia-polyfills:

import 'core-js/es6/promise';
import 'core-js/es6/function';
...

Upvotes: 1

Greg Gum
Greg Gum

Reputation: 37909

I don't know that this is the best way, but it worked for me:

In webpack.config.js:

const webpack = require("webpack");

...

plugins: [
  new webpack.ProvidePlugin({
      Promise: 'es6-promise-promise'
  })

]

Note that the "es6-promise-promise" lib was installed.

More on Plug-ins:

Upvotes: 0

Related Questions