我尝试使用CRACO实现topLevelAwait,同时添加一些polyfill,但它无法检测topLevelAwait设置的代码行。如果我取出polyfill的代码行,我只得到polyfill错误,而不是topLevelAwait is not enabled错误,如果我添加polyfill的行,polyfill工作,但我有topLevelAwait is not enabled错误。
这就是我的 *craco。config.js * 文件看起来像:
module.exports = {
webpack: {
configure: {
experiments: {
topLevelAwait: true,
},
},
configure: webpackConfig => {
const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
({ constructor }) => constructor && constructor.name === 'ModuleScopePlugin'
);
webpackConfig.resolve.plugins.splice(scopePluginIndex, 1);
webpackConfig['resolve'] = {
fallback: {
path: require.resolve("path-browserify"),
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
'crypto-browserify': require.resolve('crypto-browserify'),
os: require.resolve("os-browserify/browser"),
url: require.resolve("url/"),
assert: require.resolve("assert/"),
},
}
return webpackConfig;
},
},
};
所有的帮助是赞赏,谢谢。
1条答案
按热度按时间798qvoo81#
我遇到了类似的问题,使用
overrideWebpackConfig
钩子覆盖了配置: