Hi Sage Community
Whilst developing my latest website using Sage I stumbled upon the following challenge:
I needed to add a custom/vendor .js script that was not available using bower. After dumping the file in assets/scripts/ and running
gulp --production
I realised that this file was not being written to dist/scripts/.
After searching online I finally found the solution and thought I would post it here incase anyone else was experiencing the same issue.
Copy and paste your script in assets/scripts/
Example: assets/scripts/custom.js
Open up assets/manifest.json in your favourite text editor and add the following:
{ "dependencies": { "main.js": { "files": [ "scripts/main.js" ], "main": true }, "main.css": { "files": [ "styles/main.less" ], "main": true }, "editor-style.css": { "files": [ "styles/editor-style.less" ] }, "jquery.js": { "bower": ["jquery"] }, "modernizr.js": { "bower": ["modernizr"] }, "custom.js": { "vendor": ["assets/scripts/custom.js"] }, "config": { "devUrl": "http://localhost/www.generositypays.org/cms/" } } }
For clarity, I added these lines:
"custom.js": { "vendor": ["assets/scripts/custom.js"] },
Include your custom script by adding the following code to lib/assets.php around line 125 after wp_enqueue_script(‘sage_js’, asset_path(‘scripts/main.js’), [], null, true);
wp_enqueue_script('custom', asset_path('scripts/custom.js'), [], null, true);
Now build by running the command gulp --production
You should now see you script in the dist/scripts/ directory.
Good luck!