【发布时间】:2015-06-10 08:52:59
【问题描述】:
我的应用程序将给定语言的消息对象加载到应用程序中。我的结构是这样的:
/lang
/en.js (100 kb file)
/ru.js (100 kb file)
/... many more
app.js (this is `MyApp` as below)
语言文件非常大,所以我想创建单独的包,然后你只包含你需要的文件<script src="lang/en.js"></script>。语言也可以随时在应用程序内“切换”。
我如何告诉 browserify 为所有语言文件构建主应用程序和单独的包,并且仍然允许 MyApp 到 require 这些语言文件?
function MyApp(lang) {
this.messages = {};
this.switchLang(lang);
};
MyApp.prototype.loadLang = function(lang) {
this.messages = require('./lang/' + lang + '.js');
};
MyApp.prototype.switchLang = function(lang) {
this.lang = lang;
this.loadLang(lang);
};
MyApp.prototype.sayHello = function() {
alert(this.messages.HELLO);
};
module.exports = MyApp;
【问题讨论】:
标签: javascript browserify commonjs