使用 Aurelia-Webpack 插件时如何包含 ES6 Promise?
How to include an ES6 Promise when using the Aurelia-Webpack plugin?
我正在使用带有 Webpack 2.0 插件的 Aurelia 1.1。这在 Chrome 中工作正常,但在 IE 中,没有承诺。
所以我收到一条错误消息:
var startPromise = new Promise(function (resolve) {
return startResolve = resolve;
});
我已经用 npm 下载了 es6 polyfill,但我不知道如何告诉 webpack 包含它以便它可以普遍使用。
我应该如何包含这个 polyfill?
我不知道这是最好的方法,但它对我有用:
在webpack.config.js中:
const webpack = require("webpack");
...
plugins: [
new webpack.ProvidePlugin({
Promise: 'es6-promise-promise'
})
]
请注意 "es6-promise-promise" lib 已安装。
关于 Plug-ins 的更多信息:
ES6 应用通常包含 polyfill(例如 core-js
)。这应该在每个应用程序之前完成一次,尽可能早,在其他库之前:
import 'core-js/es6';
考虑到 aurelia-polyfills
已被使用,可以有选择地包含 polyfills 以不与 the ones from aurelia-polyfills
冲突:
import 'core-js/es6/promise';
import 'core-js/es6/function';
...
我正在使用带有 Webpack 2.0 插件的 Aurelia 1.1。这在 Chrome 中工作正常,但在 IE 中,没有承诺。
所以我收到一条错误消息:
var startPromise = new Promise(function (resolve) {
return startResolve = resolve;
});
我已经用 npm 下载了 es6 polyfill,但我不知道如何告诉 webpack 包含它以便它可以普遍使用。
我应该如何包含这个 polyfill?
我不知道这是最好的方法,但它对我有用:
在webpack.config.js中:
const webpack = require("webpack");
...
plugins: [
new webpack.ProvidePlugin({
Promise: 'es6-promise-promise'
})
]
请注意 "es6-promise-promise" lib 已安装。
关于 Plug-ins 的更多信息:
ES6 应用通常包含 polyfill(例如 core-js
)。这应该在每个应用程序之前完成一次,尽可能早,在其他库之前:
import 'core-js/es6';
考虑到 aurelia-polyfills
已被使用,可以有选择地包含 polyfills 以不与 the ones from aurelia-polyfills
冲突:
import 'core-js/es6/promise';
import 'core-js/es6/function';
...