2016-04-20 22 views
3
the remote file is a single components compiled by webpack 
    the wenpack config as follow: 


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

コンポーネントがcdnにあります。 私はロードして、反応でリモートコンポーネントを使用します。 とどのように擬似コードのようにそれを使用します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; 

答えて

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!') 
}); 
+0

最初に、あなたの質問のためのthaks、私はあなたと同じ考えを見つけた、https://github.com/yariv/ReactScriptLoader – abnerCrack

+0

Webpackの作成者の1人がここで同じ答えを持っていたので、私はこれを+1している:https ://github.com/webpack/webpack/issues/240#issuecomment-40686135 – Ryan