drupal-webpack
v0.3.3
Published
This package facilitates the installation of Webpack 5 for Drupal 8+.
Downloads
41
Readme
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.
# Drupal root path
root: 'web'
# Determine which packages to compile.
# A value of '*' means that all packages of the specified type will be treated.
packages:
module: '*'
theme: '*'
# File Extensions
extensions:
scripts: '.js'
styles: '.scss'
# Underscore skipping
skipUnderscoreFiles: true
# Configurations for modules
modules:
# JS files source & destination.
# JS files result in minified versions. Setting the same destination as the source will not overwrite original files.
scripts:
source: 'js'
destination: 'js'
# SCSS files source & destination.
styles:
source: 'scss'
destination: 'css'
# Configurations for themes
themes:
# Single Directory Components folder.
# CSS & Minified JS will be generated in the same location as found SCSS & JS.
components: 'components'
# JS files source & destination.
# JS files result in minified versions. Setting the same destination as the source will not overwrite original files.
scripts:
source: 'js'
destination: 'js'
# SCSS files source & destination.
styles:
source: 'scss'
destination: 'css'Below are examples of using webpack after it has been configured:
Compile all assets for configured packages
This will compile assets for all packages configured in the packages key of the configuration.
By default, this is all found custom modules and themes.
npm exec webpackCompile assets for a given custom theme
npm exec webpack -- --env theme=my_custom_themeCompile assets for all configured custom themes
npm exec webpack -- --env packageType=themeCompile assets for a given custom module
npm exec webpack -- --env module=my_custom_moduleCompile assets for all configured custom modules
npm exec webpack -- --env packageType=moduleCompiled 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.

