0

I am trying to add a jQuery Plugin waypoint.js to my theme. I did the following:

File: app/design/frontend/name/themename/requirejs_config.js

var config = {
    map: {
        '*': {
            waypoint:'js/waypoint'
        }
    }
};

JS File is here: app/design/frontend/name/themename/web/js/waypoint.js

I call it in a phtml file:

require(['jquery','waypoint'],function($){

});

The Chrome debugging tool shows me an error now, can't find that waypoing.js in the static folder here:

Uncaught SyntaxError: Unexpected identifier require.js:1895 GET pub/static/frontend/name/themename/de_CH/waypoint.js

The file waypoint.js does not exist in that folder. How to bring it there?

3 Answers 3

0

Under pub/static/_requirejs/frontend/Namespace/Theme/en_US, delete the file requirejs-config.js.

and run this command

php bin/magento setup:static-content:deploy
0

DEVELOPER MODE: Make sure to turn on the developer mode when you are in the development environment. Then Magento generates the static content files run time (when the static resource is requested) and place them in the pub/static directory accordingly.

To do that:

  1. Apache .htaccess file of the root directory you are using [MAGENTO_ROOT]/.htaccess or [MAGENTO_ROOT]/pub/.htaccess, uncomment the line

    SetEnv MAGE_MODE developer

  2. NginX: Uncomment the following line on the server {} directive

    server { listen 80; server_name SERVER_NAME; set $MAGE_ROOT ROOT_DIR; set $MAGE_MODE developer; #This line will turn on developer mode include file.conf; }

PRODUCTION MODE: You must turn off the developer mode when going live. and use production mode. This way Magento won't create missing static content in the pub/static directory. Hence you will get 404 page. You have to manually deploy the static content.

`SetEnv MAGE_MODE production # Apache .htaccess`
`set $MAGE_MODE production; # NginX`

For every deployment you make to the live server, you have to run

`php bin/magento setup:static-content:deploy`

So that Magento will go through each module and generate the necessary static files in the pub/static directory

0

I found an easy way that seems to work.

First requirejs_config.js is not needed. I remove it.

All you need to do is ad the js file here: app/design/frontend/name/themename/web/js/waypoint.js

Now you can can call it from every phtml file. Just wrap this around it:

require(['jquery','js/waypoint'],function($){

});

This works for me. Probably I will add my js in a phtml file on the end, maybe footer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.