在webpack中使用require.ensure时如何处理超时

时间:2017-02-04 06:17:30

标签: webpack webpack-2

import collections from collections import Counter import numpy as np import matplotlib.pyplot as plt list1 = ["red", "blue", "yellow", "yellow", "blue", "green", "pink", "red"] list2 = ["black", "black", "yellow", "red", "blue", "pink", "pink", "red", "purple", "white", "red", "orange", "red", "brown", "brown"] list_total = list1 + list2 c1 = Counter(list1) c2 = Counter(list2) c_all = Counter(list_total) labels_total, values_total = zip(*Counter(list_total).most_common()) indexes = np.arange(len(labels_total)) plt.bar(indexes, values_total) plt.show() 放置webpackrequire.ensure以加载异步块。

在webpack2中,我们可以使用import加载异步块。它返回一个promise,所以如果加载失败,我们可以捕获错误并做一些事情。

import

如果使用import("./module").then(module => { return module.default; }).catch(err => { console.log("Chunk loading failed"); }); 。如何在加载异步块失败时处理超时或出错?

0 个答案:

没有答案