JSON

[Òë]¿ªÊ¼Ñ§Ï°webpack(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2015-11-10 15:01 ÎÒÒªÆÀÂÛ( )

¶©ÔÄÒ³ÃæºÍ×ÊÁÏÒ³Ãæ¹²ÓÃÐí¶à´úÂ루ÏñReactÒÔ¼°ÆäËûµÄÑùʽºÍ×é¼þµÈ£©¡£webpack¿ÉÒÔ³é³öËûÃǹ²ÓõĴúÂ룬Ȼºó´òÒ»¸öͨÓðüÔÚ¸÷¸öÒ³Ã滺´æ¡£ // webpack.config.jsvar webpack = require('webpack');var commonsPlugin

¶©ÔÄÒ³ÃæºÍ×ÊÁÏÒ³Ãæ¹²ÓÃÐí¶à´úÂ루ÏñReactÒÔ¼°ÆäËûµÄÑùʽºÍ×é¼þµÈ£©¡£webpack¿ÉÒÔ³é³öËûÃǹ²ÓõĴúÂ룬Ȼºó´òÒ»¸öͨÓðüÔÚ¸÷¸öÒ³Ã滺´æ¡£

// webpack.config.js var webpack = require('webpack'); var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js'); module.exports = { entry: { Profile: './profile.js', Feed: './feed.js' }, output: { path: 'build', filename: '[name].js' // Template based on keys in entry above }, plugins: [commonsPlugin] };

ÔÚÉÏÒ»²½µÄscript±êǩ֮ǰ¼ÓÉÏ <script src="build/common.js"></script> £¬È»ºó¾¡ÇéÏíÊÜÃâ·ÑµÄ¸ßËÙ»º´æ°É¡£

9¡¢Òì²½¼ÓÔØ

CommonJSÊÇͬ²½µÄ£¬µ«ÊÇWebpackÌṩһ¸ö·½·¨À´Òì²½µÄÖ¸¶¨ÒÀÀµ¡£ÕâÔÚ¿Í»§¶Ë·ÓÉÖкÜÓÐÓã¬Ã¿¸öÒ³Ã涼ÐèҪ·ÓÉ£¬Äã²»ÏëÖ±µ½ÄãÕæÕýÐèÒªËûÃǵÄʱºò²ÅÏÂÔØÏà¹Ø¹¦ÄÜ¡£

Ö¸¶¨ÄãÏëÒì²½¼ÓÔØµÄ ·Ö¸îµã £¬±ÈÈ磺

if (window.location.pathname === '/feed') { showLoadingState(); require.ensure([], function() { // this syntax is weird but it works hideLoadingState(); require('./feed').show(); // when this function is called, the module is guaranteed to be synchronously available. }); } else if (window.location.pathname === '/profile') { showLoadingState(); require.ensure([], function() { hideLoadingState(); require('./profile').show(); }); }

webpack»á×ö½ÓÏÂÀ´µÄ¹¤×÷£¬²¢ÇÒ²úÉú¶îÍâµÄ¿éÎļþ£¬È»ºó¼ÓÔØËûÃÇ¡£

µ±Äã¼ÓÔØÕâЩÎļþµ½htmlµÄscript±êÇ©£¬webpack¼Ù¶¨ËûÃÇÔÚ¸ùĿ¼£¬Äã¿ÉÒÔͨ¹ý output.publicPath À´¶¨Òå:

// webpack.config.js output: { path: "/home/proj/public/assets", //path to where webpack will build your stuff publicPath: "/assets/" //path that will be considered when requiring your files } ÆäËû×ÊÔ´

¿´Ò»ÏÂÕæʵµÄ°¸Àý£ºÒ»¸ö³É¹¦µÄÍŶÓÊÇÈçºÎʹÓÃwebpackµÄ¡£ÕâÊÇPete HuntÔÚÈ«Çò¿ªÔ´´ó»áÉϹØÓÚIntagramʹÓõÄwebpackµÄÌÖÂÛ£º ¡£

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  •  JSONÈëÃż¶Ñ§Ï°×ܽá-JSONÊý¾Ý½á¹¹

    JSONÈëÃż¶Ñ§Ï°×ܽá-JSONÊý¾Ý½á¹¹

    2016-02-25 11:05

  • ASP.NET Web API 2 ·µ»Ø Json¸ñʽ

    ASP.NET Web API 2 ·µ»Ø Json¸ñʽ

    2016-02-10 17:18

  • jsonѧϰ֮Èý£ºJSONArrayµÄÓ¦ÓÃ

    jsonѧϰ֮Èý£ºJSONArrayµÄÓ¦ÓÃ

    2016-01-30 12:32

  • iOSÈëÃÅѧϰ(json½âÎö)

    iOSÈëÃÅѧϰ(json½âÎö)

    2016-01-26 09:00

ÍøÓѵãÆÀ
¼