【问题标题】:How to load remote file in webpack如何在 webpack 中加载远程文件
【发布时间】:2016-08-12 22:10:41
【问题描述】:
 the remote file is a single components compiled by webpack 
  the wenpack config as follow:


    {
     .....
     library: library
    ,externals: externals
    ,libraryTarget: "umd"
     .....
    }

组件在cdn中, 我想在反应中加载和使用远程组件。 以及如何像伪代码一样使用它:

   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;

【问题讨论】:

标签: asynchronous reactjs webpack


【解决方案1】:
【解决方案2】:
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!')
});

【讨论】:

【解决方案3】:

正如我在另一篇文章中所说:我四处寻找解决方案,但大多数提案都是基于外部的,这对我来说是无效的。

更多信息在这里:https://stackoverflow.com/a/62603539/8650621

基本上,我使用了一个单独的 JS 文件,它负责将所需的文件下载到本地目录中。然后 WebPack 扫描该目录并将下载的文件与应用程序捆绑在一起。

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    相关资源
    最近更新 更多