I want to require a file. Its path is in some config:
//config.js
module.exports = "/home/css/style.css";
//entry.js
var path = require(./config.js);
require("style!css!" + path);
Uncaught Error: Cannot find module "."
How can I require files with path that can take root /
directory?
You'll have to use require.ensure
For ex.:
function handleRouteChange(path) {
require(['/views/' + path], function(PageView) {
app.setView(new PageView());
});
}
changes to:
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...
}
}
Source: https://gist.github.com/xjamundx/b1c800e9282e16a6a18e#the-routing-code-old-and-new
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With