Asynchronous 如何在网页包中加载远程文件
组件位于cdn中, 我想在react中加载和使用远程组件。 以及如何像伪代码一样使用它:Asynchronous 如何在网页包中加载远程文件,asynchronous,reactjs,webpack,Asynchronous,Reactjs,Webpack,组件位于cdn中, 我想在react中加载和使用远程组件。 以及如何像伪代码一样使用它: the remote file is a single components compiled by webpack the wenpack config as follow: { ..... library: library ,externals: externals ,libraryTarget: "umd" ..... } a
the remote file is a single components compiled by webpack
the wenpack config as follow:
{
.....
library: library
,externals: externals
,libraryTarget: "umd"
.....
}
ajax->get a json>{components name}>使用该名称加载romote文件
例如,json包含我需要加载botton.min.js的botton
var Button=reuqire('http://botton.min.js')
类应用程序扩展了React.Component{
render(){
返回(
);
}
}
导出默认应用程序;
也许您可以从以下资源中找到解决方案:
基本上,我使用了一个单独的JS文件,负责将所需文件下载到本地目录中。然后WebPack扫描此目录,并将下载的文件与应用程序捆绑在一起。首先,thaks根据您的要求,我发现了一个与您相同的想法,我给这个a+1,因为WebPack的一个创建者在这里有相同的答案:可能是
ajax -> get a json > { components name } > use the name to load romote file
for example the json have the botton i need to load the botton.min.js
var Button = reuqire('http://botton.min.js')
class App extends React.Component {
render() {
return (
<div>
<Botton/>
</div>
);
}
}
export default App;
npm install scriptjs
var $script = require("scriptjs");
$script("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", function() {
$('body').html('It works!')
});