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


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

die Komponenten im CDN, ich möchte laden und verwenden Sie die Remote-Komponenten in reagieren laden. und wie es wie die Pseudo-Code zu verwenden:Wie Remote-Datei in 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; 

Antwort

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

zuerst, thaks für Ihre Frage, ich fand die gleiche Idee wie Sie, https://github.com/yariv/ReactScriptLoader – abnerCrack

+0

Ich gebe dies ein +1, weil einer der Schöpfer von Webpack hatte die gleiche Antwort hier: https : //github.com/webpack/webpack/issues/240#issuecomment-40686135 – Ryan