gpt4 book ai didi

node.js - 如果一个 npm 包附带多个 dist 文件夹,我如何知道在构建我的应用程序时使用了哪个?

转载 作者:行者123 更新时间:2023-12-05 06:57:58 25 4
gpt4 key购买 nike

我在我的应用程序中使用了一个 npm 包 (aurelia-google-maps)。该软件包附带 AMD、System、CommonJS、Native Modules 和 ES2015 dist 文件夹,如下所示:

/node_modules/
/aurelia-google-maps/
/dist/
/amd
/system
/native-modules
/es2015
/commonjs

在我的 typescript 应用程序中,我只是将所有类和函数导入为:

import {Configure} from "aurelia-google-maps"

有什么方法可以让我在构建应用程序时找出使用的是哪个发行版?

最佳答案

我认为如果没有构建工具的帮助,您无法确定它。可以分两步完成:

  • 使用 type of 检查运行时代码中变量的可用性:
const distType = typeof DIST_TYPE !== 'undefined' ? DIST_TYPE : void 0;
  • 配置构建工具以将 DIST_TYPE 替换为分发目标

然后您可以通过 distType 变量在普通代码中使用它。


对于 typescript ,你只需要一个额外的声明

declare const DIST_TYPE: string | undefined;

关于node.js - 如果一个 npm 包附带多个 dist 文件夹,我如何知道在构建我的应用程序时使用了哪个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64752982/

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