我想要一个文件。它的路径是在一些配置中:
//config.js
module.exports = "/home/css/style.css";
//entry.js
var path = require(./config.js);
require("style!css!" + path);
Uncaught Error: Cannot find module "."
如何要求文件包含可以生成root /
目录的路径?
答案 0 :(得分:1)
您必须使用require.ensure
例如:
function handleRouteChange(path) {
require(['/views/' + path], function(PageView) {
app.setView(new PageView());
});
}
更改为:
function loadPage(PageView) {
app.setView(new PageView());
}
function handleRouteChange(path) {
switch (path) {
case 'settings':
require(['/views/settings'], loadPage);
break;
case 'transfer':
require(['/views/transfer'], loadPage);
break;
case 'wallet':
require(['/views/wallet'], loadPage);
break;
default:
// you could either require everything here as a last resort or just leave it...
}
}
来源:https://gist.github.com/xjamundx/b1c800e9282e16a6a18e#the-routing-code-old-and-new