On this page
- Install pre-requisites
- Common workflows
- JavaScript code (since Drupal 10)
- JavaScript code (for Drupal 9)
- Reviewing changes to CKEditor 5 build files
- CSS code
- Building core CSS
- Building Drupal core's forked jQuery UI
- Updating third-party dependencies
- Updating JavaScript dependencies other than CKEditor or modernizr
- Updating CKEditor 5
- Updating modernizr
- Quick Reference
- Compile ("transpile") JavaScript ES6 files (only for Drupal 9)
- Check JavaScript
- Compile PostCSS files
- Check Stylesheets
- Compile both JavaScript and PostCSS files
- Compile jQuery UI
- Run Tests
- Update third-party libraries
- Un-minify CKEditor 5 JavaScript files with development mode
Frontend Developer tools for Drupal core
Install pre-requisites
- Node.js - ensure that you are using at least the latest long-term support (LTS) release of Node.js, which is available at the Node.js downloads page. Alternatively, you can install Node.js via a package manager on many OS platforms.
- Yarn - we use yarn for managing dependencies and running build scripts. Different versions of Drupal require different versions of yarn. Run
corepack enableas a one-time setup step, so that Node can automatically choose the correct version. - Install package dependencies - from the root of your Drupal folder:
cd core && yarn install
Common workflows
JavaScript code (since Drupal 10)
Drupal 10 does not transpile, because browser support is now good enough to use modern JavaScript without the need for transpiling, but JavaScript in core must be linted, and developing for CKEditor 5 requires webpack.
Once the pre-requisites are installed, edit the .js file you want, and when the code is ready, make sure the code is formatted correctly with:
# Command to run from inside the core/ folder.
yarn lint:core-js-passingJavaScript code (for Drupal 9)
Drupal core adopted modern features of the JavaScript language before those features were universally supported in browsers, so Drupal 9 used babel to transpile modern JavaScript to a version compatible with older browsers. The convention was that all JavaScript must be written in a file with the extension .es6.js, and the corresponding .js file for legacy browsers would be automatically created by the build tools detailed below. For CSS Drupal core also supports PostCSS and build tools will handle any file with the extension .pcss.css and create the corresponding .css file when running the build command.
Once the pre-requisites are installed, when working on a patch, the overall Drupal 9 workflow is:
- launch a watcher for changes in
.es6.jsfiles, - lint the code and fix formatting errors,
- compile (or "transpile") the
.es6.jscode to.jsfiles, - and finally create the patch to send to drupal.org.
# Commands to run from inside the core/ folder.
# Listen to changes on all *.es6.js files and
# automatically compile the *.js file.
yarn run watch:js
# Work on the JavaScript until satisfied,
# stop the watch command.
# Before creating the patch to send to drupal.org
yarn run lint:core-js-passing
# All errors and warning displayed must be fixed
# before sending the patch to drupal.org.
# Some errors can be automatically corrected,
# such as code formatting by adding the '--fix'
# parameter to the lint command.
yarn run lint:core-js-passing --fix
# Once there are no more syntax errors build
# all .js files with
yarn run build:jsAt this point you can create a patch to send to Drupal.org issue queue. It is very important to run the linter on JavaScript code so that the quality of our code doesn't degrade over time.
If you need to be able to debug the JavaScript code you can replace the first command with yarn run watch:js-dev and the .js file will contain the source map so you can see the .es6.js file in the browser developer tools. For the source maps to be used you must disable JavaScript aggregation.
If you want to only compile a specific file you can pass the --file flag to the build command:
yarn run build:js -- --file misc/drupal.es6.js
Reviewing changes to CKEditor 5 build files
We can reduce the risk of security issues being added by new JavasScript dependencies by reviewing un-minified build assets.
1. Create a branch for the development build.
2. Build the files by running the development build command and commit the changes. This build command will un-minify the build files.
yarn build:ckeditor5-dev
git commit -am 'Unminified build assets'3. Go back to the branch with the new changes you want to review the build files for.
4. Run the development build command again on this branch and commit the changes.
yarn build:ckeditor5-dev
git commit -am 'Unminified build assets'6. Now you can compare this against the branch created earlier.
git diff <Your_Branch> <Branch_To_Compare_With> -- core/modules/ckeditor5/js
CSS code
When developing core CSS locally you can use the watcher to make changes and have them compiled as you save.
cd core
yarn install
yarn run watch:css
This watcher will only watch changes in files with the .pcss.css extension.
Building core CSS
To build all CSS run yarn run build:css. This will create .css versions of the .pcss.css files.
If you want to only compile a specific file you can pass the --file flag:
yarn run build:css -- --file themes/seven/css/base/elements.pcss.css
Check the coding standard using:
yarn run lint:css Building Drupal core's forked jQuery UI
When modifying the forked copy of jQuery UI that ships with Drupal core, build the minified JS files using yarn run build:jqueryui .
Updating third-party dependencies
Core's CKEditor and modernizr dependencies are not maintained with package.json, because they require custom builds.
Updating JavaScript dependencies other than CKEditor or modernizr
To check if there are updates to a third party dependency:
- Run
yarn outdatedto find outdated packages- Update
package.jsonversion requirement if necessary (when updating dependencies in non-production branch).- Development dependencies: required for updating major releases.
- Production dependencies: required for updating minor and major releases.
- Run
yarn upgrade <package>
- Update
- Run
yarn vendor-updateto automatically:- Copy all required files to the
core/assets/vendorfolder - Update the libraries definition in
core.libraries.ymlwith the correct version and License URL
- Copy all required files to the
- Run
yarn buildto ensure any changes to the third party libraries are reflected in build files - Check that all changes were made correctly:
- No missing vendor files
- URLs to licences and versions in the core.libraries.yml are correct
- Run
yarn lint:cssandyarn lint:core-js-passingto ensure any updates to the lint rules are not failing with existing code
Updating CKEditor 5
- Increase the package constraints for the CKEditor 5 dependencies as needed in
core/package.json(all packages with the@ckeditornamespace). - Perform a clean installation of core's yarn dependencies:
cd core rm -rf node_modules yarn install - Update the vendor assets:
yarn run vendor-update. - Run the CKEditor 5 build:
yarn run build:ckeditor5. - Run
yarn run build:ckeditor5-types(this step is needed for compiling a map of CKEditor 5 JSDoc types in a format that is compatible with IDEs).
Updating modernizr
Copied from /core/assets/vendor/modernizr/README.md.
To update modernizr:
For some reason the link in the core file https://modernizr.com/download/?-details-inputtypes-addtest-mq-prefixed-prefixes-setclasses-teststyles always produces a 3.6.0 version when using the Build option. Browse to the same URL and use the Command Line Config option to Download the config JSON file modernizr-config.json. Following the instructions from modernizr's documentation:
sudo npm install -g npm
npm install -g modernizr
modernizr -c modernizr-config.json // This is the file downloaded from http://modernizr.com/downloadThis produces a modernizr.js file that should be renamed to modernizr.min.js and copied to core/assets/vendor/modernizr/modernizr.min.js. Also remember to update the version number of Modernizer in core/core.libraries.yml.
Quick Reference
package.json in the DRUPAL_ROOT/core has some useful script commands for Drupal core development. Run these commands in the core directory.
Compile ("transpile") JavaScript ES6 files (only for Drupal 9)
yarn build:jsyarn build:js-devyarn watch:jsyarn watch:js-dev
Check JavaScript
yarn lint:core-jsyarn lint:core-js-passingyarn lint:core-js-statsyarn prettier
Compile PostCSS files
yarn build:cssyarn watch:css
Check Stylesheets
yarn lint:cssyarn lint:css-checkstyle
Compile both JavaScript and PostCSS files
yarn buildyarn watch
Compile jQuery UI
yarn build:jqueryui
Run Tests
yarn test:nightwatch.
Update third-party libraries
yarn upgrade <package>yarn vendor-update
Un-minify CKEditor 5 JavaScript files with development mode
yarn build:ckeditor5-devyarn watch:ckeditor5-dev
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion