Magento 2. Add a custom javascript to a theme.

by Peter D.

Before adding custom js, make sure you already created a custom theme based on one of Argento themes.

With the Argento theme you receive the opportunity to add a custom JS file in Magento 2 that will be automatically included on all pages.

Please follow the steps.

#1 Create a new directory in your custom Argento sub-theme:

app/design/frontend/Local/argento-[essence|flat]-custom/web/js

#2 Create argento-custom.js inside the js folder.

#3 Add script skeleton:

define([
    'jquery',
    'domReady!'
], function($) {
    alert("Hi, I'm custom js file");
});

#4 Save the file and run the following bash commands to deploy the script:

cd magento/root/folder
php bin/magento setup:static-content:deploy

Recent articles