【问题标题】:Export webpack function in typescript在打字稿中导出 webpack 功能
【发布时间】:2021-12-19 03:21:38
【问题描述】:

webpack 文档显示 type 从配置 function 返回,但不显示参数 envargv 的类型。目前我必须将它们键入为 any,但是 envargv 的实际类型是什么?

const configuration = (env: any, argv: any): Configuration => ({
  mode: 'production',
  entry: './foo.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'foo.bundle.js',
  },
  ...
});

【问题讨论】:

    标签: javascript typescript webpack


    【解决方案1】:

    它们都是any,因为它们都来自 webpack cli 参数,所以不可能在编译时提前知道类型(除非你严格知道你总是会传递某些参数并且 强制将类型设为您声明的类型)

    Webpack Environment Variables docs 可能有助于更好地理解。

    【讨论】:

    • 谢谢,我之前找不到任何结论性的东西。
    猜你喜欢
    • 1970-01-01
    • 2016-02-10
    • 2013-03-17
    • 1970-01-01
    • 2022-01-24
    • 2016-10-27
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    相关资源
    最近更新 更多