Shopify / slate

Slate is a toolkit for developing Shopify themes. It's designed to assist your workflow and speed up the process of developing, testing, and deploying themes.
https://shopify.github.io/slate
MIT License
1.28k stars 364 forks source link

theme.collection.js not loaded #943

Closed marcinkrzeminski closed 5 years ago

marcinkrzeminski commented 5 years ago

Problem

Following the docs, I have created a collection.js file within the src/scripts/templates/ directory. Unfortunately, the file template.collection.js is not created / loaded. I do have the src/templates/collection.liquid file in my project. I also tried to start and stop the yarn watch process without any luck. As a temporary fix, I moved my collection dedicated code into the theme.js but I guess this is not the way to do it if I have a collection dedicated JS code.

Replication steps

  1. Create collection.js within your `src/scripts/ directory and simply put console.log(1) for testing
  2. yarn watch
  3. Go to any collection page

More Information

I run yarn deploy to create the file and deploy it but it's not loaded. I don't see it in the Network tab nor the code seems to be executed.

My Setup:

node version 8.12.0 yarn version 1.12.1

dan-gamble commented 5 years ago

Hey @marcinkrzeminski, the collection.js should be inside scripts/templates so you have scripts/templates/collection.js. Then after that run yarn start and it should work when on the collection template.

marcinkrzeminski commented 5 years ago

Hey @dan-gamble,

thanks for your reply. I just edited my original post, and I do have it in src/scripts/templates/ but it's still not working. Did you miss the src within the path intentionally? On my installation Slate keeps all the files inside the src directory so I think I shouldn't create anything outside having in mind that for example the src/sripts/templates/product.js works fine.

dan-gamble commented 5 years ago

The src missing was intentional yes, i probably should have included it.

Could you show me what your dist/snippets/script-tags.liquid looks like?

marcinkrzeminski commented 5 years ago

Hey again,

I checked the dist/snippets/script-tags.liquid and the collection if statement is in place and I can see the collection related JS working now. That's super weird. I had other issues with Slate in the meantime so I've reinstalled all the npm packages as well as did the OS restart. Seems like this kind of fix never gets old 🤦‍♂️. Thanks for your time Dan.

dan-gamble commented 5 years ago

No worries @marcinkrzeminski, glad you got it sorted :)

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.