{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/webpack/issues/5489","repository_url":"https://api.github.com/repos/webpack/webpack","labels_url":"https://api.github.com/repos/webpack/webpack/issues/5489/labels{/name}","comments_url":"https://api.github.com/repos/webpack/webpack/issues/5489/comments","events_url":"https://api.github.com/repos/webpack/webpack/issues/5489/events","html_url":"https://github.com/webpack/webpack/issues/5489","id":249319240,"node_id":"MDU6SXNzdWUyNDkzMTkyNDA=","number":5489,"title":"When using AMD output, use AMD for code-split chunks as well","user":{"login":"onigoetz","id":309594,"node_id":"MDQ6VXNlcjMwOTU5NA==","avatar_url":"https://avatars0.githubusercontent.com/u/309594?v=4","gravatar_id":"","url":"https://api.github.com/users/onigoetz","html_url":"https://github.com/onigoetz","followers_url":"https://api.github.com/users/onigoetz/followers","following_url":"https://api.github.com/users/onigoetz/following{/other_user}","gists_url":"https://api.github.com/users/onigoetz/gists{/gist_id}","starred_url":"https://api.github.com/users/onigoetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onigoetz/subscriptions","organizations_url":"https://api.github.com/users/onigoetz/orgs","repos_url":"https://api.github.com/users/onigoetz/repos","events_url":"https://api.github.com/users/onigoetz/events{/privacy}","received_events_url":"https://api.github.com/users/onigoetz/received_events","type":"User","site_admin":false},"labels":[{"id":428473406,"node_id":"MDU6TGFiZWw0Mjg0NzM0MDY=","url":"https://api.github.com/repos/webpack/webpack/labels/P4:%20Nice%20To%20Have","name":"P4: Nice To Have","color":"fef2c0","default":false},{"id":1089822,"node_id":"MDU6TGFiZWwxMDg5ODIy","url":"https://api.github.com/repos/webpack/webpack/labels/enhancement","name":"enhancement","color":"DDDDDD","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-08-10T11:42:41Z","updated_at":"2018-11-19T14:45:55Z","closed_at":null,"author_association":"NONE","body":"<!-- Please don't delete this template or we'll close your issue -->\r\n<!-- Before creating an issue please make sure you are using the latest version of webpack. -->\r\n<!-- Also consider trying the webpack@beta version, maybe it's already fixed. -->\r\n\r\n**Do you want to request a *feature* or report a *bug*?**\r\n\r\nA new feature that would improve code-splitting with externals.\r\n\r\n<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->\r\n<!-- Issues which contain questions or support requests will be closed. -->\r\n\r\n**What is the current behavior?**\r\n\r\n_Context :_\r\nAn application which is build with multiple sub-applications which are each built with Webpack, and the \"orchestration\" of loading all this is done through requirejs.\r\nOne of the things with this platform, is that react is provided through requirejs so that each plugin can reuse a single global library instead of re-loading it for each app. (Any other library could be provided globally, I use react as the example here)\r\n_/context_\r\n\r\nWhen we generate a library in amd with some externals and code-splitting. \r\nThe thing is that externals are defined only at the main level even though it's the code-split part that need those externals.\r\n\r\nExample : \r\n\r\n```js\r\n// main.min.js\r\ndefine(['react'], function(a) { /* Doesn't actually need react yet */ });\r\n\r\n// 1.main.min.js\r\nwebpackJsonp([0],{3: function() { /* actually needs react */});\r\n```\r\n\r\nWouldn't it be better if it was able to generate it this way ?\r\n\r\n```js\r\n// main.min.js\r\ndefine(function() { /* Doesn't actually need react yet */ });\r\n\r\n// 1.main.min.js\r\ndefine([\"react\"], function(a) {\r\n  return {\r\n    chunkIds: [0],\r\n    moreModules: {3: function() { /* actually needs react */}}\r\n  }\r\n});\r\n```\r\n\r\nAdvantages are : \r\n- no custom logic to load modules, requirejs knows how to do it.\r\n- external dependencies are loaded when they're actually needed\r\n- no need to specify a name for the jsonp function as it's done through requirejs\r\n\r\nProblem with the current implementation: \r\n- externals might be loaded too early, which defeats the purpose of code splitting and lazy loading of those parts.\r\n\r\n**If the current behavior is a bug, please provide the steps to reproduce.**\r\n\r\nIt isn't a bug, just the normal behaviour that could be more optimal\r\n\r\n<!-- A great way to do this is to provide your configuration via a GitHub gist. -->\r\n<!-- Best provide a minimal reproduceable repo -->\r\n<!-- If your issue is caused by a plugin or loader file the issue on the plugin/loader repo -->\r\n\r\n**What is the expected behavior?**\r\n\r\nTo load externals once they are needed\r\n\r\n**If this is a feature request, what is motivation or use case for changing the behavior?**\r\n\r\nMy motivation is that I have an application that supports plugins, each of those can be implemented with any techology, React, jquery, vanilla js ... while they mostly use React today, we don't know what the future holds for us. Which is why we want to be able to lazily load libraries once they are actually used.\r\n\r\n**Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.**\r\n\r\nWe use webpack 3.5.2\r\n"},"comment":{"url":"https://api.github.com/repos/webpack/webpack/issues/comments/439916625","html_url":"https://github.com/webpack/webpack/issues/5489#issuecomment-439916625","issue_url":"https://api.github.com/repos/webpack/webpack/issues/5489","id":439916625,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTkxNjYyNQ==","user":{"login":"DeTeam","id":72801,"node_id":"MDQ6VXNlcjcyODAx","avatar_url":"https://avatars1.githubusercontent.com/u/72801?v=4","gravatar_id":"","url":"https://api.github.com/users/DeTeam","html_url":"https://github.com/DeTeam","followers_url":"https://api.github.com/users/DeTeam/followers","following_url":"https://api.github.com/users/DeTeam/following{/other_user}","gists_url":"https://api.github.com/users/DeTeam/gists{/gist_id}","starred_url":"https://api.github.com/users/DeTeam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DeTeam/subscriptions","organizations_url":"https://api.github.com/users/DeTeam/orgs","repos_url":"https://api.github.com/users/DeTeam/repos","events_url":"https://api.github.com/users/DeTeam/events{/privacy}","received_events_url":"https://api.github.com/users/DeTeam/received_events","type":"User","site_admin":false},"created_at":"2018-11-19T14:45:55Z","updated_at":"2018-11-19T14:45:55Z","author_association":"CONTRIBUTOR","body":"@Aghassi I spent a bit of time on reading webpack internals and feel like there're few things to check out:\r\n\r\n- AMD template plugin (the one you mentioned)\r\n- `lib/web/JsonpChunkTemplatePlugin.js` — this one's gonna be used for separate chunks, as I understand\r\n\r\nOne way to tackle this would be to:\r\n\r\n1. Create custom plugins for chunk and and output templates\r\n1. Experiment with how the templates work until you get the desired output (AMD with splitchunks)\r\n1. Change existing internal templates to what's implemented\r\n\r\n^^^ I wanted to take this route, but still learning some of the internals of webpack for a better background knowledge"}}
{"actor":{"display_login":"DeTeam"}}