-
Notifications
You must be signed in to change notification settings - Fork 801
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
"react-hot-loader/babel" includes file path in production mode #789
Comments
Duplicates #692, please check your configuration, ie does dead code elimination works. |
Hi there I am also having this issue, I have checked dead code elimination is working Proof is here: and see this (not uglified) https://github.com/opr/spooky/blob/281f9962b4b19b29fae1dca5dc45212e56e78fa8/assets/js/dist/spooky.js and also see this (uglified) https://github.com/opr/spooky/blob/281f9962b4b19b29fae1dca5dc45212e56e78fa8/assets/js/dist/spooky.min.js for evidence of dead code elimination working. Here is my webpack.config Thanks! |
You have proven, that webpack could remove "dead" branches, and by "dead" I mean with const conditions.
It does exist, thus it is not constant, thus could not be evaluated during the complication, and next removed as a dead code.
Try replace new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}), Into.
Now we have exact variable name, and webpack will do the rest of magic. |
Hi @theKashey thanks for your response I made the change you suggested to the webpack.DefinePlugin. I looked inside the uglified bundle and could not find that string - this is the uglified bundle again for reference: https://github.com/opr/spooky/blob/109ccb46ee3a316be471b0cc68acb4c9cfb1423a/assets/js/dist/spooky.min.js If you observe line 11 here: you will see I have tested the environment is being set correctly. Inside the uglified bundle I can still see paths and I can also see my "BANANAS" test. (Please don't worry about the non-uglified bundle as I am not using the DefinePlugin there) I hope this provides more information. |
I have discovered that my problem was the same as #602 (comment) Thank you for the help and apologies for missing this! (PS what do you mean that I have 2 versions of react?) |
PS: React also has |
still have the issue. |
@lili21 - sorry, but RTFM
You have to
|
I think |
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}) doesn't work for me.
|
That's why I linked an issue about "webpack is not doing it". And providing NODE_ENV is super important. |
Still, providing NODE_ENV=production doesn't work, |
You shall not only set NODE_ENV, but also "define" that env for webpack. 2 comments above. |
Only |
I can confirm that what @theKashey 's saying resolves the issue. Setting // Npm script
"webpack --env.mode production"
// Webpack config
module.exports = (env) => {}
// In Webpack config plugins
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.mode),
}), It seems that Thanks @theKashey. |
I'm have the same problem, I try use workaround @m7dev but... dont work for me, i'm using:
Someone has a workaround or fix for that? |
My issue was that https://github.com/gaearon/react-hot-loader/blob/master/babel.js was using the dev version even when building for production. So it was not about setting up |
Just it, work for me, but I using a solution a litle diferent, take a look: on my
to check mode. I create a:
And below I do it:
Now work very well ;) tnks @davincho |
Description
I found that "react-hot-loader/babel" includes files path in production mode, also when "process.env.NODE_ENV" is defined to "production".
After removing from webpack configuration and babelrc, everything looks fine.
Expected behavior
There shouldn't be any paths in production mode.
Actual behavior
"react-hot-loader/babel" includes files path, ignoring the environment type.
Environment
React Hot Loader version: next (today refreshed)
node -v
: v9.4.0npm -v
: 5.6.0Operating system: Windows 10
Browser and version: Firefox Nightly 59.0a1
My webpack config to prevent including file paths inside the compiled scripts.
The text was updated successfully, but these errors were encountered: