{"id":412,"date":"2025-01-10T13:37:10","date_gmt":"2025-01-10T18:37:10","guid":{"rendered":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/?page_id=412"},"modified":"2025-02-20T13:52:14","modified_gmt":"2025-02-20T18:52:14","slug":"webpack-config-js","status":"publish","type":"page","link":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/handbook\/bu-tools\/webpack-config-js\/","title":{"rendered":"Webpack"},"content":{"rendered":"\n<p><a href=\"https:\/\/webpack.js.org\/\">Webpack<\/a> is a free, open-source tool that bundles JavaScript, CSS, and images for websites. It&#8217;s used to create static assets that serve content to a browser.<\/p>\n\n\n\n<p>For its build process, WordPress uses webpack. You\u2019ll find it in the @wordpress\/scripts package, which gets output alongside the blocks that come from the @wordpress\/create-block package.<\/p>\n\n\n\n<p class=\"has-background has-pale-pink-background-color\">in development: there are currently two files to try to have one file that had config values unique to that repo, and one webpack file that might end up getting moved to an id-build-tools kind of repo and imported that way instead.<\/p>\n\n\n\n<p>Both the theme starter and plugin starter have 2 files in the root folder that allow you to customize your build: <\/p>\n\n\n\n<h2>webpack.config.js<\/h2>\n\n\n\n<p>This file extends the <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/blob\/trunk\/packages\/scripts\/config\/webpack.config.js\">default wp-scripts webpack config file<\/a>. Code here is merged with the default rules using the package <code>webpack-merge<\/code>.<\/p>\n\n\n\n<p>There are many ways to configure webpack. Some of the settings we are using at the time of this writing are outlined below:<\/p>\n\n\n\n<ul><li><code><a href=\"https:\/\/webpack.js.org\/configuration\/module\/\">module<\/a><\/code> determines how the different types of modules within a project will be treated.<\/li><li><code><a href=\"https:\/\/webpack.js.org\/configuration\/module\/#modulerules\">rules<\/a><\/code> modify how the module is created. They can apply loaders to the module, or modify the parser.<\/li><li><code><a href=\"http:\/\/link https:\/\/webpack.js.org\/configuration\/stats\/#stats-presets\">stats<\/a><\/code> lets you precisely control what bundle information gets displayed.<\/li><li><a href=\"https:\/\/webpack.js.org\/configuration\/devtool\/\"><code>devtool<\/code><\/a> controls if and how source maps are generated.<\/li><li><code><a href=\"https:\/\/webpack.js.org\/configuration\/entry-context\/\">entry<\/a><\/code> is where webpack looks to start building the bundle. The context is an absolute string to the directory that contains the entry files.<\/li><li><a href=\"https:\/\/webpack.js.org\/configuration\/plugins\/\"><code>plugins<\/code><\/a> is used to customize the webpack build process in a variety of ways.<\/li><\/ul>\n\n\n\n<p>When you run a build, webpack will run twice: the first time to build blocks, the second to build all other scripts and styles.<\/p>\n\n\n\n<h2>webpack.customizations.js<\/h2>\n\n\n\n<p>Developers can make changes to the entry points and paths listed in this file to load new assets from node packages or to add new stylesheets to be compiled by webpack. Further instructions can be found in the file comments.<\/p>\n\n\n\n<h2>Terminal Output<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/webpack.js.org\/configuration\/stats\/\">stats option<\/a> lets you precisely control what bundle information gets displayed. This can be a nice middle ground if you don&#8217;t want to use quiet or noInfo because you want some bundle information, but not all of it.<\/p>\n\n\n\n<p>Here are some examples of different outputs:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"142\" src=\"\/gutenberg\/files\/2025\/01\/modules-1024x142.png\" alt=\"\" class=\"wp-image-437\" srcset=\"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/modules-1024x142.png 1024w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/modules-636x88.png 636w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/modules-768x106.png 768w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/modules.png 1284w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>modules: true<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"113\" src=\"\/gutenberg\/files\/2025\/01\/chunk-1024x113.png\" alt=\"\" class=\"wp-image-433\" srcset=\"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunk-1024x113.png 1024w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunk-636x70.png 636w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunk-768x85.png 768w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunk-1536x170.png 1536w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunk-2048x227.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>chunks: true<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"100\" src=\"\/gutenberg\/files\/2025\/01\/chunkGroups-1024x100.png\" alt=\"\" class=\"wp-image-434\" srcset=\"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunkGroups-1024x100.png 1024w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunkGroups-636x62.png 636w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunkGroups-768x75.png 768w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunkGroups-1500x148.png 1500w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/chunkGroups.png 1520w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>chunkGroups: true<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"241\" src=\"\/gutenberg\/files\/2025\/01\/assets-1024x241.png\" alt=\"\" class=\"wp-image-439\" srcset=\"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/assets-1024x241.png 1024w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/assets-636x150.png 636w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/assets-768x181.png 768w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/assets.png 1326w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>assets: true<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"103\" src=\"\/gutenberg\/files\/2025\/01\/entrypoints-1024x103.png\" alt=\"\" class=\"wp-image-435\" srcset=\"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/entrypoints-1024x103.png 1024w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/entrypoints-636x64.png 636w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/entrypoints-768x77.png 768w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/entrypoints.png 1492w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>entrypoints: true<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"642\" height=\"232\" src=\"\/gutenberg\/files\/2025\/01\/logging.png\" alt=\"\" class=\"wp-image-431\" srcset=\"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/logging.png 642w, https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/files\/2025\/01\/logging-636x230.png 636w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><figcaption>logging: true<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Webpack is a free, open-source tool that bundles JavaScript, CSS, and images for websites. It&#8217;s used to create static assets that serve content to a browser. For its build process, WordPress uses webpack. You\u2019ll find it in the @wordpress\/scripts package, which gets output alongside the blocks that come from the @wordpress\/create-block package. in development: there [&hellip;]<\/p>\n","protected":false},"author":9175,"featured_media":0,"parent":577,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"status-is-a-reserved-term":[],"assignee":[],"_links":{"self":[{"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/pages\/412"}],"collection":[{"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/users\/9175"}],"replies":[{"embeddable":true,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":11,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/pages\/412\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/pages\/412\/revisions\/492"}],"up":[{"embeddable":true,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/pages\/577"}],"wp:attachment":[{"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"status-is-a-reserved-term","embeddable":true,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/status-is-a-reserved-term?post=412"},{"taxonomy":"assignee","embeddable":true,"href":"https:\/\/id-developer-upgrade-58.cms-devl.bu.edu\/gutenberg\/wp-json\/wp\/v2\/assignee?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}