gpt4 book ai didi

webpack - 同步需要动态路径

转载 作者:行者123 更新时间:2023-12-04 04:37:46 26 4
gpt4 key购买 nike

我想要一个文件。它的路径在一些配置中:

//config.js
module.exports = "/home/css/style.css";

//entry.js
var path = require(./config.js);
require("style!css!" + path);

Uncaught Error: Cannot find module "."

我该如何要求带有路径的文件可以采用 /根目录?

最佳答案

您必须使用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

关于webpack - 同步需要动态路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34636196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com