Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Integrates Drupal with webpack.

What does it do?

The module allows developers to have their Drupal libraries bundled by webpack. It makes it easy to import npm packages and use modern javascript that will work across a variety of browsers (with Webpack Babel).

Dependencies

  • drush 9+
  • yarn

Setup

Your project needs to have a package.json file somewhere up the directory tree. In drupal-composer projects it is a common practice to place one next to the project-wide composer.json. If you don't have such a file yarn init -yp will generate an empty one.

Once you've got package.json, add the module as a local dependency.

yarn add file:./web/modules/contrib/webpack

Usage

Add webpack: true to your library definition in module_name.libraries.yml (example).

Local development

For local development, start the dev server with drush webpack:serve. The module will detect it and inject the development version (with live reload). Make sure you don't have Bigpipe or JS aggregation enabled locally. It is also important to either run it outside of docker containers or set up port forwarding.

When running inside a container add the --docker. This alone will work if the webserver is ran in the same container as drush. Otherwise, drupal will need some additional info in order to detect the server, i.e. --dev-server-host=cli where cli the hostname (or the service name from docker-compose) of the container that runs drush.

Building for prod

On the server, add drush webpack:build to your after-deploy steps. The bundles will be written to public://webpack (sites/default/files by default) and included automatically.

The output directory can be changed at /admin/config/webpack/settings, to put the files under source control for instance. If you set it to a path that is outside of the public files folder make sure to export your site's config after building (details).

Building for contrib

If you're building a contrib module and you don't want to force the end sites to have to set up webpack you can bundle a single library along with all its npm dependencies. The library will work on a plain drupal installation. However, when the end site installs webpack at some point it will detect the lib and do the bundling on the project level, enabling the long-term vendor caching and bundle splitting.

To build a single library set its definition like this and run drush webpack:build-single module_name/library_name.

Keep in mind that only libraries licensed under GPL 2 or greater can be uploaded to drupal.org.

How does it work?

Setup steps and the modus operandi have been described in Progressive Decoupling - The why and the how at Decoupled Drupal Days NY 2018 (video).

Should I use it now?

It's still in alpha but the usage won't change much.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Jan 2024
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
3.0.1 Stable Jan 25, 2024
3.0.0 Stable Jan 23, 2024
3.x-dev Dev Jan 23, 2024