-
Notifications
You must be signed in to change notification settings - Fork 10
browserify support #8
Comments
Features to implementA certain subset of the features could be made to work in the browser.
Features to skipThe following will not work in the browser.
Implementation approachesThere are two approaches to make this work.
Implementing using browserify transformsSo one way to implement this is to author and use browserify transforms that can read I'm not sure whether we would have to write our own transforms or could re-use some. Implementing using server-side help.You can use something like The browser config loader can then just read the correct config from global scope. This means the disk reading, NODE_ENV resolution, etc will be done on the server as part of rendering the html. Choices.I recommend the server-side help solution as browserify transforms are pretty complicated. I do not have the bandwidth to implement it this week. cc @lxe for suggestings on how to implement this in bedrock cc @orbiteleven for suggestions on how this fits into toolshed |
Are you trying to load the server configuration on the client side? If so, you can export it either as a route: app.get('/config.json', function (req, res) {
res.json(config);
}); Or as template variables: app.get('/config', function (req, res) {
res.render('my_template', {
config: config
});
}); Are you trying to have client-specific configuration variables available to the client scripts? You can possibly run zero-config as one of your gulp steps that generates a config.js prior to browserifying, then bundle the config.js, and use it via require('config.js')? |
We want Ideally it would read all the Having it be an async HTTP request or having it be baked into some kind of gulp step would not be acceptable. It needs to have a subset of the interface with |
We need to define "#justwork". What exactly should this code do on the client?: var fetchConfig = require('zero-config');
var config = fetchConfig(__dirname, {
dc: NODE_ENV === 'production' ?
'/etc/playdoh/datacenter' : null
}); We can't read config from "file" or "directory" on the client side (well.. technically we can, but I'm not sure this is useful for our usecase), requiring either a route requesting which returns the config, or somehow pre-populating the config before browserifying. |
What about brfs for handling configuration loading client-side? |
@mlmorg I think browserifying our secrets files and serving that to browsers is a BAD IDEA (TM). |
@mlmorg @Raynos I've been playing around with brfs transform. One limitation/feature of brfs, is that it only overrides the Also config-chain is very difficult to browserify (browserify actually ends up failing on index.js due to lack of semicolons). Also, there's no clean way that I know of to conditionally detect whether brfs needs to be loaded at all. It's kind of wasteful to load brfs for projects that don't need client-side loading. Nonetheless, there's a way to make zero-config browserifiable by directly Reference PR pending. |
It should be noted that browser code probably wants a seperate entry point. Namely a We will have to refactor this code to break out the shared / browser / node modules. |
Conveniently, config-chain is unable to load anything at all after browserifying (if no changes are made to zero-config and config-chain). Something like this works: var zeroConfig = require('zero-config');
var fs = require('fs');
// This always loads an empty config object
var config = zeroConfig(__dirname);
// Add stuff to it
config.set(JSON.parse(fs.readFileSync(__dirname + '/config/browser/common.json')));
console.log(config.get()); |
Let's not "conveniently" rely config-chain not loading anything. Let's duplicate some more of the implementation to make the browser implementation leaner and less "works on my machine (tm)". |
I completely agree with this. I'm just exploring options and reporting what I find. Just notifying that "there is a way" |
Ping. Did you come up with anything for this? |
As far as I know it's not implemented. |
zero-config doesn't work in browserified files
I was hoping to use zero-config on a SPA that will live on web-toolshed.
cc @orbiteleven @lxe @sh1mmer @Raynos
The text was updated successfully, but these errors were encountered: