Skip to content

Instantly share code, notes, and snippets.

@jed
Created July 3, 2012 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jed/3038799 to your computer and use it in GitHub Desktop.
Save jed/3038799 to your computer and use it in GitHub Desktop.
browserify-alias-test
node_modules
lib.js
module.exports = {
hello: "Hello"
}
module.exports = {
hello: "こんにちは"
}
{
"name": "alias-test",
"version": "0.0.0",
"dependencies": {
"browserify": "~1.13.5"
},
"scripts": {
"test": "node ./test.js"
}
}
var locale = require("locale")
console.log(locale.hello)
var fs = require("fs")
, browserify = require("browserify")
, app = browserify()
app.alias("/node_modules/locale/index.js", "/locales/en")
app.addEntry("./src.js")
fs.writeFileSync("./lib.js", app.bundle())
require("./lib")
@jed
Copy link
Author

jed commented Jul 3, 2012

this is a test case for using browserify's .alias method to build localized javascript bundles.

the idea is that you should be able to run the browserification process for each locale, and create localized bundles that ship only the assets required from the app.

unfortunately, i can't get it to work, as documented in browserify/browserify#184. would love to hear any ideas on how to get past this. as an alternative i could just symlink /locales/index.js to each locale file before building, but such an ugly hack shouldn't be needed.

to test this out, just run this one-liner:

git clone git://gist.github.com/3038799.git && cd 3038799 && npm i && npm test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment