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
process.browser and suggestions #35
Comments
It's recommended to use the // componentsList.js
module.exports = require('fs')
.readdirSync('./components')
.map(function(c) { return c.replace('.js', ''); });
// componentsList.web.js
module.exports = require
.context('../components').keys()
.map(function(c) { return c.replace('./', '').replace('.js', ''); });
// ComponentsLoader.js
var ComponentLoader = {
get: function(name) {
return require('../components/' + name);
},
available: function() {
var components;
return require("./componentsList");
}
};
module.exports = ComponentLoader; It would not include server side code into browser bundle. Elsewise testing yes require.context(...).keys() should be also availible on server side with enhanced-require. It's a bug that it is missing. So I fixed it and you can use the same code and server and client side: var ComponentLoader = {
get: function(name) {
return require('../components/' + name);
},
available: function() {
var components;
components = require.context('../components').keys();
return components.map(function(fileName) {
return fileName.replace('./', '').replace('.js', '');
});
}
};
module.exports = ComponentLoader; |
Haha, thanks. I like the fact that I can do 2. on both client and server now. :) I didn't know about |
So it should be :) The problem with |
@sokra One more question, if you don't mind: For debugging purposes, I'd love it if each require()d module arrived in a separate file (much easier to set breakpoints in chrome's dev tools, than scrolling through the massive webpack file with all my components). How would you do this? Would you use |
This make chrome dev tools display each module like a separate file.
|
Perfect, I'll try this in a few minutes when I'm home. Thanks! |
And... how cool is it? ;) |
Beautiful! :D Now I just need to hook up your connect middleware into my node server to remove that compile step... I might even try out the Hot Module Reloading, while I'm at it. |
Hey @sokra
I just hacked together this little module: (not related to components/components)
I am using the
ComponentLoader.available()
function to return every component, so I can use them in a user interface.It works surprisingly well. My main grief points are the following:
process.browser
or some other utility variable to tell us where our code is running?components = require.context('../components').keys();
in the browser and the server, but got the following error:Error:
So is it possible to use the exact same code on both server and client?
Thanks!
The text was updated successfully, but these errors were encountered: