Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Cannot reference JS asset files in Liquid #409

Closed
t-kelly opened this issue Feb 22, 2018 · 10 comments
Closed

Cannot reference JS asset files in Liquid #409

t-kelly opened this issue Feb 22, 2018 · 10 comments
Assignees

Comments

@t-kelly
Copy link
Contributor

t-kelly commented Feb 22, 2018

Followup to #407 and #408

Problem

There is currently a bug when including a script asset reference, e.g. <script src="{{ '../assets/scripts/modernizr.js' | asset_url }}"></script>, where the src gets transformed into {{ [object Object] | asset_url }} and not {{ 'modernizr.js' | asset_url }}.

Replication steps

How to replicate the problem. Screenshots or video?

More Information

This transformation happens so that in dev build (slate-tools start) we can reference the localhost, and then in prod build (slate-tools build) we can reference the lib uploaded on the Shopify CDN. To avoid this transformation and always reference the Shopify CDN, developers could use double quotes, e.g. {{ "../assets/vendors/modernizr.js" | asset_url }}, but we should also support the above approach.

@YCMitch
Copy link

YCMitch commented Jun 27, 2018

Wait so for my own sanity, it's currently impossible to include a script from the assets folder, right?

Like the tutorial for multiple currencies is currently not actually achievable in Slate?

@t-kelly
Copy link
Contributor Author

t-kelly commented Jun 27, 2018

@MitchEff -- correct. In the mean time, just import that file like any other JS file into your main theme JS file:

src/assets/layout/theme.js

import 'jquery.currencies.min.js';

@ghost
Copy link

ghost commented Aug 16, 2018

It also seems to be stripping stylesheet_tag and script_tag filters.

input

{{ '../assets/static/some-asset.js' | asset_url | script_tag }} 
{{ '../assets/static/some-asset.scss' | asset_url | stylesheet_tag  }} 

output

https://localhost:8080/some-asset.js
https://localhost:8080/some-asset.scss

@t-kelly t-kelly added the !!! label Aug 22, 2018
@numediaweb
Copy link

Also stuck on this: the documentation of Slate needs huge improvement :(

undefined
./layout/theme.liquid
Module not found: Error: Can't resolve './admin-panel.js' in '/Users/aidrissi/apps/trassig-theme-dev/src/layout'
 @ ./layout/theme.liquid ./admin-panel.js
 @ . sync ^\.\/layout.*\.liquid$
 @ ../node_modules/@shopify/slate-tools/tools/webpack/static-files-glob.js
 @ multi ../node_modules/@shopify/slate-tools/tools/webpack/hot-client.js ../node_modules/@shopify/slate-tools/tools/webpack/static-files-glob.js

@sebbean
Copy link

sebbean commented Aug 27, 2018

@numediaweb can you show how you're referencing the .js file in your theme.liquid?

@numediaweb
Copy link

@sebbean I fixed it by switching single quotes to double.. wasn't easy to find though in documentation :(

@callaginn
Copy link

callaginn commented Aug 29, 2018

@numediaweb Did you figure out where to put your css or js sources? I've tried putting them in various locations in the src folder, such as src/assets/scripts, src/assets/templates, src/assets/static, but the slate-tools watcher doesn't do anything with them. I even tried moving them to the /dist folder, but they don't upload automatically.

I've only found two options that work, but they aren't the best solution:

  • Compile JS using CodeKit and upload via the web interface (too slow). Haven't found a way to compile JS via yarn / slate-tools yet.
  • Insert CSS into src/assets/styles/theme.scss as @import statements. I've also found I can insert css into theme.scss.liquid. Is there a way to insert a new css link though?

All of this was really straightforward with Slate v0, but Slate v1 is throwing me for a loop.

@sebbean
Copy link

sebbean commented Sep 14, 2018

@callaginn i'm putting them in my static folder actually src/assets/static/vueapp.js
seems to work ok - only on a full deploy.

npm start doesn't seem to see any file changes in there while i'm deving

@t-kelly
Copy link
Contributor Author

t-kelly commented Oct 25, 2018

@t-kelly t-kelly closed this as completed Oct 25, 2018
@lock
Copy link

lock bot commented Nov 24, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants