-
-
Notifications
You must be signed in to change notification settings - Fork 590
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
feat(replace): typeofReplacements option #1084
Conversation
fcc15a4
to
04895fa
Compare
It's very tricky to get these snapshots to line up when working on Windows. Everything is passing, but would be appreciated if someone with a unix machine could update the snapshots here. Alternatively when I next have access to WSL I can take a look. Update: Finally got the snapshots updated over WSL on my other machine. |
The concept is sound. Not so sure about the option name. To anyone not familiar with the use case, I don't think the option name conveys what the option does. |
Thanks for the review @shellscape I've renamed the feature to |
Sounds good to me |
|
||
> Snapshot 1 | ||
|
||
`if (typeof process !== 'undefined' && "production" === 'production') {␊ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't typeof process
be transformed to 'object'
? :
if ('object' !== 'undefined' && "production" === 'production') {
Rollup Plugin Name:
plugin-replace
This PR contains:
Are tests included?
Breaking Changes?
Description
Currently
process.env.NODE_ENV
replacements only replace that exact string. But as came up in reactjs/react-transition-group#777, it can be useful for browser code to guard these replacements like:by default this plugin will not handle these other guards properly.
This PR adds a new
typeofReplacements: true
option (disabled by default, although it would be nice to enable by default in future), which will replace thetypeof process
with"object"
in the case of identifier member expression replacement strings.The user only needs to define
process.env.NODE_ENV
as the replacement key, and it will automatically expand the parent object typeof replacements when using this option.See the README for a further example.