gpt4 book ai didi

javascript - 异步 webpack 配置

转载 作者:搜寻专家 更新时间:2023-10-31 23:40:45 26 4
gpt4 key购买 nike

我无法让它工作。请帮助:)

(documentation 说 webpack 可以处理 Promises)

这有效:

var compiler = webpack(webpackConfig)

但是有了 promise 我会出错

var compiler = webpack(new Promise(function(resolve, reject) {
setTimeout(() => { resolve(webpackConfig) }, 100);
}));

我得到的错误是:

C:\path\node_modules\webpack\lib\webpack.js:19
throw new
WebpackOptionsValidationError(webpackOptionsValidationErrors);
^

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration misses the property 'entry'.
object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
The entry point(s) of the compilation.
at webpack (C:\path\node_modules\webpack\lib\webpack.js:19:9)
at Object.<anonymous> (C:\path\build\dev-server.js:27:16)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
at startup (bootstrap_node.js:144:9)
at bootstrap_node.js:467:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我做错了什么?

最佳答案

它是处理 Promise 配置的 webpack CLI。如果您使用的是 Node API,则需要自行处理。

在您的示例中,这将是:

const configPromise = new Promise(function(resolve, reject) {
setTimeout(() => { resolve(webpackConfig) }, 1000);
});

configPromise
.then(webpack) // Passes the config to webpack
.then(compiler => {
// Do the work with the compiler
});

这样做的想法是能够在配置中轻松地进行异步处理,首先使用 Node API 时不存在这个问题。

关于javascript - 异步 webpack 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43327486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com