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
Play nice with transpilers by using variable requires (fixes #345) #358
Conversation
@@ -883,7 +884,8 @@ util.parseFile = function(fullFilename) { | |||
configObject = require(fullFilename); | |||
} | |||
else if (extension === 'iced') { | |||
Iced = require("iced-coffee-script"); | |||
var dep = "iced-coffee-script" |
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.
Javascript hoists variables, and having individual var dep
gives the misleading impression that these are different things, when they are all the same variable.
A better pattern would be to define var dep = undefined;
at the top of the function and use that variable without (misleadingly) re-defining it in each instance.
Even better would be to have a block at the top of the file like this
// Define soft dependencies so transpilers don't include everything
var ICED_COFFEE_SCRIPT = "iced-coffee-script";
var JS_YAML = "js-yaml"
...
Then simply use these variables instead of the hardcoded strings require(ICED_COFFEE_SCRIPT);
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.
+1 to that. I blindly implemented the isolated solution given for one variable in the issue thread. I'll push an update now.
I've taken this config.js but still getting Is this working for others? |
@jonohodgson I eventually discovered that it's extremely hard to get node-config working with Webpack (or any transpiler) in the browser environment in any meaningful way. This is because there is no In Webpack you can avoid that specific error using Ultimately we settled on exposing a shimmed |
~~Cheers~!~~ Edit: Nevermind, I think I see the issue being face above. Sorry. |
This PR appears to be answered by #118 |
@jdmarshall #118 is an old issue about CSON support. Try again? |
Yeah looks like they were referencing their own ticket. |
Given the comment about that says essentially "this wasn't going to work in the end anyway": #358 (comment) I'm closing this. |
As discussed in #345 this PR moves all conditional requires in
lib/config.js
to use a variable module name. This allows transpilers like Webpack to properly resolve the dependency graph.