我正在开发一个自定义的钢网组件,它将有一个下拉式的选项,从我的后台api获取。使用fetchapi我得到了要显示的数据。但是这个组件将被集成在Angular应用中,所以,我如何识别它是用于开发还是生产,因为我必须基于这个来获取数据。我不知道如何获得这个信息,我在哪里使用我的模板组件。
angular - my-component.html
<div>
<p>This is example of stenciljs</p>
<my-dropdown (onChange)="onSelect($event)"></my-dropdown>
</div>
你可以使用 Build
的上下文。
import { Build } from '@stencil/core';
if (Build.isDev) {
// ...
} else {
// this is a prod build
}
死代码消除将从你的prod bundle中删除代码,所以你不必担心开发相关代码的暴露。