-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip flow-runtime imports in production mode #36
Comments
Hmm, why do you import the module if you're not using it? Was it to work around the issue in #26 ? If so that problem should be fixed. |
Well that's when I first noticed the limitation. I don't need that particular work-around anymore, but I think the use-case is valid. For example, if I want to use import t from 'flow-runtime';
import * as mobx from 'mobx';
import flowRuntimeMobx from 'flow-runtime-mobx';
flowRuntimeMobx(t, mobx); // only need to do this once. This works of course, but I've now made I can flag these under |
Ah ok, this is a bit tricky. Let's say we introduced a new option called I'm not sure there's a way to do this automatically without turning it into a footgun. What I typically do is have a file called something like if (process.env.NODE_ENV === 'development') {
require('./devMode'); // eslint-disable-line
} In |
I was thinking more like
This is a suitable workaround for small-scale projects, but is not great at scale. I work with 15 web engineers across several different projects in a monorepo. In order to evangelize and increase Flow adoption, I'm looking to make it as painless as possible to adopt it. Having to add workarounds to use this feature would be a hard sell. The |
If I'm understanding you correctly, you'd ideally like to be able to do something like this: import t from 'flow-runtime';
function demo (a) {
t.string().assert(a); // direct usage, not a transformation of a flow annotation
return a;
} and have the calls to function demo (a) {
return a;
} Is that correct? It's pretty trivial in the basic case but gets impossibly complicated/impossible as soon as you pass the result of a call to import t from 'flow-runtime';
function demo (a) {
return t.typeOf(a);
} |
Hm, yeah I didn't think of that. |
Another point is that you could just do this directly, without putting it in a separate file: import t from 'flow-runtime';
import * as mobx from 'mobx';
import flowRuntimeMobx from 'flow-runtime-mobx';
if (process.env.NODE_ENV === 'development') {
flowRuntimeMobx(t, mobx); // only need to do this once.
} Again, DCE and tree shaking should remove all of that. |
You could also use something like babel-plugin-discard-module-references with babel-plugin-minify-replace to remove dev-only imports |
Yeah, I think it's out of scope for |
This is a:
Which concerns:
What is the current behaviour?
It's currently not possible to strip developer-added
flow-runtime
imports in production. This limitation makes it difficult to manually addflow-runtime
checks for teams that only type check in development mode, as it makes theflow-runtime
package a requirement in production.What is the expected behaviour?
If possible there should be a user-configurable way to remove user-specified
flow-runtime
imports / code in environments (prod / stage / test / etc).Which package versions are you using?
0.2.1
The text was updated successfully, but these errors were encountered: