javascript - Export / import without using dependency in Reactjs -
i working on reactjs. have created 2 components named app , layout separately in 2 two javascript files. app should use layout.
//index.html <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <script src="react-0.14.7.js"></script> <script src="react-dom-0.14.7.js"></script> <script src="browser.min.js"></script> </head> <body> <div id="root"></div> <script type="text/babel" src="/js/components/app/app.js" ></script> </body> </html>
.
//app.js var layout = require('/js/components/layout/layout.js'); var app = react.createclass({ render() { return( <div> <p>hello app</p> <layout/> </div> ) } }); reactdom.render( <app />, document.getelementbyid('root') );
.
//layout.js var layout= react.createclass({ render:function(){ return( <div> <p>hi layout</p> </div> ) }, }); //even tried 'export default layout'
when used import layout ('/js/components/layout/layout.js'). gave error unexpected token import.
with use of require('/js/components/layout/layout.js'). gave error require not defined.
i tried many ways layout app solution found use browserify, node , npm, webpack...
but want executed neither dependency packages nor jars. there way can done?
thanks in advance.
the short answer no. both browserify , webpack module bundlers , file bundling you. i'd recommend understand first purpose of both tools.
the first thing browserify website tells sole purpose:
browserify lets require('modules') in browser bundling of dependencies.
and same story webpack:
webpack module bundler modern javascript applications. when webpack processes application, recursively builds dependency graph includes every module application needs, packages of modules small number of bundles - 1 - loaded browser.
those short descriptions of both of them.
Comments
Post a Comment