Created
September 10, 2014 18:27
-
-
Save appsforartists/0870a67838b580e75b27 to your computer and use it in GitHub Desktop.
Bug in DefinePlugin?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// … | |
// SERVER_IP is defined in Webpack, since the client can't run my-local-ip | |
"API_BASE_URL": "http://" + (require("my-local-ip")() || SERVER_IP) + ":8082/", | |
// … | |
/* this is being exported from webpack as: | |
// SERVER_IP is defined in Webpack, since the client can't run my-local-ip | |
"API_BASE_URL": "http://" + (__webpack_require__(197)() || (192.168.10.106)) + ":8082/", | |
and causing a syntax error: | |
Uncaught SyntaxError: Unexpected number jsx.js:11100 | |
my-local-ip exports a string. wtf? | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// … | |
"plugins": [ | |
// … | |
new Webpack.DefinePlugin({ | |
"SERVER_IP": require("my-local-ip")() | |
}), | |
], | |
//… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case anyone ever ends up here due to the same problem, the string needs to be enclosed in quotes.
If DefinePlugin sees a string, it will attempt to replace it verbatim into the source.
You can do
'"' + require("my-local-ip")() + '"'
or simplyJSON.stringify(require("my-local-ip")())
.