-
Notifications
You must be signed in to change notification settings - Fork 54
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
what's the recommended way to disable this within babelrc when compiling via webpack? #44
Comments
Are you trying to disable whole In that case you can provide Or you can use Did this help? |
Ok I don't think there is such thing as |
@michalkvasnicak unfortunately the environment variables are already used by https://babeljs.io/docs/usage/babelrc/ Most apps use development/production, so there is no opportunity there. ..Maybe there is another flag I can detect in the function I can provide to the .babelrc:
and the function:
It's not being called. What am I doing wrong? |
...my bad, the function is working. i had a typo in the path. ...i think i tried this a while back and couldn't find any clues that the code was running inside webpack, but I'll try again. |
@faceyspacey yes and you didn't receive an Error because ignore can be |
it actually doesn't look like there are any relevant environment variables I can use. Also, it won't be a solution anyone using webpack can use, as many people use webpack on the server as well. You can set environment variables if you run webpack from the commandline, but if you use the node api, I don't know of a way, as the |
If you use node api then you can define env variable just like By the way, if you are using webpack then just don't use this plugin at all. Webpack has its own |
I'm actually working on a package that must work with both a webpack and a babel server, and I'm making a boilerplate example, so I'm trying to keep it as easy as possible. That said, setting
on the server doesn't export the proper classNames to use in React components. In the past I've used |
basically you need style-loader or extract-text-webpack-plugin after css-loader for the following to work:
|
You can achieve what you want using webpack too without using this plugin. I am using webpack for client side and server side bundles in separate and it works correctly. You can see configurations here in my create-js-app repository for Class names are valid and css is exported only for client side compilation. On server side, the files are not exported at all. |
ah: |
...it worked like a charm for webpack!
...now i just need to figure out how to add it to the babelrc without affecting the client code, and without having to rewrite the babelrc in the webpack config with |
the problem with this:
is that the same environment variables will be used by the server code and the client code in development, i.e. when you generate the client code from the middleware running in the server code. |
I think that {
"plugins": [
[
"use-plugin-if-env-set",
"IS_WEBPACK",
["babel-plugin-css-modules-transform", configuration-for-css-modules-transform-plugin]
]
],
} Basically it would check if Or maybe just create your own babel plugin which will act as So basically this: import cssModulesTransformPlugin from 'babel-plugin-css-modules-transform';
export default function myCssModulesTransform(...args) {
if (process.env.IS_WEBPACK) {
return {};
}
return cssModulesTransformPlugin(...args);
} I think this approach could be simpler than the first. |
cool. I'll look into that. Thanks so much. I'm sure I'm taking up too much of your time. I'll let you know how things go... |
@faceyspacey you are welcome. I hope that I helped. Just I don't think that this option should be a part of the configuration for this plugin. There is a solution, we just need to find it. |
I'm using the following method, which I think is nice and clean, just change the 'BABEL_ENV' environment variable, and setup rules in .babelrc. The official documentation is here http://babeljs.io/docs/usage/babelrc/#env-option run with BABEL_ENV=lib babel ./src/js/File --out-dir ./lib/src {
"presets": [
"es2015",
"stage-0",
"react"
],
"env":
{
"development":
{
},
"production":
{
},
"lib":
{
"plugins": ["css-modules-transform"]
},
}
} |
Currently, I'm duplicating my babelrc in my webpack config with
babelrc: false
like this:But ultimately that's really cumbersome, especially when what I'm doing is recommending the use of
babel-plugin-css-modules-transform
for use in conjunction with my package. It means a lot of extra directions to provide developers, when otherwise things are very simple.I've tried things like using the
ignore
option using a function to no avail. It would be nice if it could be disabled with the present of a particular environment variable, such as:process.env.IS_WEBPACK === true
via an option like:
disableOnEnv: "IS_WEBPACK"
.Perhaps there is already something like this? I think a lot of people use this webpack--so an idiomatic strategy documented for that would be very useful.
The text was updated successfully, but these errors were encountered: