Skip to content
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

Rewire only in a test environment #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BenjaminVanRyseghem
Copy link

Rewire conflict with babel-plugin-wildcard.

As a workaround (which could benefits others), I make rewire run only in a test environment.

@speedskater
Copy link
Owner

@BenjaminVanRyseghem sorry for the late reply. I have just had a look at your PR.Thank you for your work in providing this feature to babel-plugin-rewire.
If I haven't missunderstood your intention, I think the same behaviour can be achieved by specifying babel-plugin-rewire only in the desired babel environment in the babelrc file.
I think this leaves the decision when to apply the plugin to the user.
Is this okay for you?

@BenjaminVanRyseghem
Copy link
Author

BenjaminVanRyseghem commented Mar 15, 2018

Thanks for your answer.

I'm kinda new to babel, and didn't find how to specify environment in babelrc.
Do you have some documentation for me?

@speedskater
Copy link
Owner

@BenjaminVanRyseghem this is a sample of one of the projects I am involved. Please keep in mind that this is not the complete configuration and it is not checked against babel 7. For further information I would recommend the babel documentation itself: https://babeljs.io/docs/usage/babelrc/

In this example we have general plugins and presets which are applicable to all environments.
Further we have a specific configuration for our karma tests which adds istanbul for code coverage and the babel-plugin-rewire.

{
	"plugins": [
		"transform-runtime",
		"syntax-flow",
		"transform-flow-strip-types"
	],
	"presets": [
		"es2015",
		"react"
	],
	"babelrc": false,
	"env": {
		"karma": {
			"plugins": [
				["istanbul", {
					"exclude": [
						"tests/**/*"
					]
				}], "rewire"
			]
		}
	}
}

Hope this is able to clarify your issue?

@BenjaminVanRyseghem
Copy link
Author

Thanks! I'll have a look 😄

I found this stating it's deprecated, but I'll give it a try asap 😄

@BenjaminVanRyseghem
Copy link
Author

sorry for the delay 😄

It works, thank you. But as it seems deprecated, it looks like this will be needed anytime soon.
What do you think?

@tfrommen
Copy link

tfrommen commented Jun 6, 2018

As Babel 7 does/will not use env any longer, this PR is actually still interesting. I'm with @BenjaminVanRyseghem here, for what it's worth. 🙂

@BenjaminVanRyseghem
Copy link
Author

ping?

@josh08h
Copy link

josh08h commented Oct 28, 2018

I'd be interested in getting this PR merged. We are on babel 7 and would like to only have this plugin run against spec files.

@theKashey
Copy link

Disabling ‘rewire’ in not-test environments could be a bad thing, as long using rewire in not-test(And not production) environment could be a good.

@Sinewyk
Copy link

Sinewyk commented May 20, 2019

I think this PR is still not needed, ok env will probably be deprecated. But nothing is stopping you from using a .babelrc.js instead of a .babelrc, and once you have a js file you can do whatever you want.

@KosnIre
Copy link

KosnIre commented Jan 26, 2022

It looks like the babel team eventually decided they would continue to support env-specific configs in babelrc, so I think this issue can be closed.

babel/babel#5276 (comment)

https://babeljs.io/docs/en/configuration#how-babel-merges-config-items

I'm on babel 7 and this config is working for me:

{
  "env": {
    "test": {
      "plugins": [
        "rewire"
      ]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants