drupal-webpack v0.2.1
Drupal Webpack 
This package facilitates the installation of Webpack 5 for Drupal 8+.
Webpack is preconfigured to handle JS & SASS found in custom Themes & Modules.
The configuration will also handle Single Directory Components found within themes.
Installation
This is a Node package and is best installed using NPM or
Yarn. You can use npm init to generate a
package.json file at the root of your project.
npm install -D drupal-webpackyarn add -D drupal-webpackUsage
Perform initial setup using the provided CLI.
npm exec druwp installyarn druwp installAfter this is done, refer to the .webpack/config.yml file that has been created and adjust it to your liking.
Below are examples of using webpack after it has been configured:
Compile assets - Will compile only for the default drupal custom theme configured
npm exec webpackCompile assets for a given custom theme
npm exec webpack -- --env theme=my_custom_themeCompile assets for all custom themes
npm exec webpack -- --env themesCompile assets for a given custom module
npm exec webpack -- --env module=my_custom_moduleCompile assets for all custom modules
npm exec webpack -- --env modulesCompiled Assets & Default Behaviour
By default, if the config.yml file is left untouched, Webpack will:
- Look for
.jsfiles atMY_MODULE/jsorMY_THEME/js.- If found, JS will be compiled and minified into respective
.min.jsfiles. - e.g.
MY_MODULE/js/MY_MODULE.jswill be compiled intoMY_MODULE/js/MY_MODULE.min.js.
- If found, JS will be compiled and minified into respective
- Look for
.scssfiles atMY_MODULE/scssorMY_THEME/scss.- If found, SCSS will be compiled and minified into respective
.cssfiles in a new/cssfolder. - e.g.
MY_MODULE/scss/MY_MODULE.scsswill be compiled intoMY_MODULE/css/MY_MODULE.css.
- If found, SCSS will be compiled and minified into respective
- In themes, any
.jsor.scssfound within a configuredcomponentsfolder for SDC will be compiled as well.
By default, files whose names start with an underscore (_) will not be compiled and are intended for imports.
e.g. _variables.scss. This can be changed in the config.yml.
