Integrates Drupal with Webpack.
yarn
installed and available in the PATHpackage.json
file somewhere up the directory tree. In drupal-composer projects, it is a common practice to place one next to the webroot and the project-wide composer.json
. Placing the file inside the webroot would work too. If you don't have such a file, yarn init -yp
will generate an empty one.
Once you've got package.json
, add the following npm dependencies.
yarn add webpack
yarn add webpack-serve --dev
webpack: true
to your library definition in module_name.libraries.yml
.
For local development, start the dev server with drush webpack:serve
and reload the page. The module will detect it and inject the development version (with live reload).
On the server, add drush webpack:build
to your after-deploy steps. The bundles will be written to public://webpack
and included automatically.
The output directory can be changed at /admin/config/webpack/settings
e.g. to put the files under source control. 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).