Fail Build Programatically

Hello, Is there a way to fail the build command through code? My use case is that I would like to assert that certain env variables are set during the build, and if not, throw. I tried adding a top level throw, however that doesn't fail the build (I assume rollup or whatever plasmo uses does not execute the files). I also tried process.exit(1) but didn't work (because the file itself is not being executed on build)
2 Replies
lab
lab•2y ago
I think this would be an useful framework feature in itself - making sure env are set etc.. re: failing the build - I think you can wrap the build logic and throw at the env check I'm thinking outloud on the env checking feature... since env are like drop-in configuration, the nature of it make it a bit to check unless we define a list of "required env" <- this would be very much per-project preference We can potentially have a .env.config file that list all the required env and check against that, or consodliate this feature into plasmo.config.ts
nahtnam
nahtnam•2y ago
While I agree ENV management is really important, I don’t think it should be that rigid (nextjs doesn’t have a system either). I’m using a library called envsafe which is pretty intuitive. However the problem is that when the env variables aren’t defined, it throws an error. With next.js, this is perfect because the pages are prerendered and they fail at the build step. However with plasmo, they don’t fail because the code isn’t executed. I think a simple solution for me is to just run ts-node config/env.ts but perhaps we should have a beforeSetup and afterSetup or something like Jest does?
Want results from more Discord servers?
Add your server