排除/替换/混淆包裹中生产版本中的某些模块

我正在使用包裹,我想从生产中排除一些代码以节省尽可能多的空间。 我使用io-ts来验证来自后端的数据。我希望这种行为出现在测试和开发构建中,而不是生产中。

(我正在使用打字稿)

// this is how it should look in non-production builds
import * as t from 'io-ts';
const schema = t.array(t.string);
export function getData(): t.TypeOf<typeof schema> {
  return fetch('/data').then(resp => resp.json()).then(data => {
    if(schema.decode(data)._tag != 'Right') throw 'ERROR!!!';
    return data;
  });
}


// this is production
export function getData() {
  return fetch('/data').then(resp => resp.json());
}

我试图将其分为两个模块...

// data-core.ts
export function getData() {
  return fetch('/data').then(resp => resp.json());
}
// data.ts
import { getData as getData_ } from './data-core';
import * as t from 'io-ts';
const schema = t.array(t.string);
export function getData(): t.TypeOf<typeof schema> {
  return getData_().then(data => {
    if(schema.decode(data)._tag != 'Right') throw 'ERROR!!!';
    return data;
  });
}

...然后,如果NODE_ENV ===“ production”,那么可以使用许多不同的插件来导入“ data-core”而不是“ data”,但是我失败了。

我还尝试使用process.env.NODE_ENV使用真实的验证器或{decode: x => ({'_tag': 'Right'})},希望树摇晃走摆脱未使用的验证器,没有运气。

nidi_3 回答:排除/替换/混淆包裹中生产版本中的某些模块

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2823572.html

大家都在问