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

Assets aren't copied with build (1.x) #407

Closed
logandeancall opened this issue Feb 21, 2018 · 8 comments
Closed

Assets aren't copied with build (1.x) #407

logandeancall opened this issue Feb 21, 2018 · 8 comments
Assignees

Comments

@logandeancall
Copy link

Problem

Assets in the src/assets/images (svg, and any custom dir) do not copy over to dist/assets on yarn build

Replication steps

Put any files in the directories mentioned above, run yarn build. Assets will not be in dist

@logandeancall logandeancall changed the title Assets aren't copied with build Assets aren't copied with build (1.x) Feb 21, 2018
@t-kelly t-kelly added the v1.x label Feb 21, 2018
@t-kelly
Copy link
Contributor

t-kelly commented Feb 21, 2018

Very true! Looks like we're only copying over svgs to the snippets folder. On it.

@t-kelly t-kelly self-assigned this Feb 21, 2018
@t-kelly t-kelly added the bug label Feb 21, 2018
@t-kelly
Copy link
Contributor

t-kelly commented Feb 22, 2018

Okay needed to validate a few things before I responded to this.

Copying static files from src/assets to dist/assets

Currently, src/assets/vendors is the only folder that has its contents copied directly to the dist/assets folder, e.g. src/assets/vendors/modernizr.js gets copied to dist/assets/modernizr.js.

In general, scripts should be imported into your main JS bundle through src/assets/scripts/theme.js and not via a Liquid file. Webpack will then be able to do what it does best and split dependencies into multiple bundles. These bundle <script> tags are injected into dist/layout/*.liquid files upon build.

There is currently a bug when including a script asset reference, e.g. {{ '../assets/vendors/modernizr.js' | asset_url }}, where it gets transformed into {{ [Object object] | asset_url }} and not {{ 'modernizr.js' | asset_url }}. 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, use double quotes, e.g. {{ "../assets/vendors/modernizr.js" | asset_url }}.

All other files and folders in the src/assets/ folder need to be referenced from an entry point, e.g. theme.js,

I think it might be an idea to change vendors to static? For me, vendors implies vendor JS and not any kind of file?

Referencing images in the src/assets/images/ folder

You can currently include image found in your src/assets/images/ in your theme liquid by referencing it with a relative path, e.g. <img src='{{ '../assets/images/lamp.png' | asset_url }}>'. This will get changed to <img src='{{ "lamp.png" | asset_url }}>' on build.

Referencing SVGs

The assets/svgs folder contents are copied to the dist/snippets/ folder and have their extension changed from .svg to .liquid. This is so you can include these SVGs inline in the page the same way you would a snippet, e.g. {% include 'icon-plus' %}. You could also include the svg the same as described above for an image, but then you don't have as much flexibility with the SVG like changing its color.

Referencing Fonts

Font's can be referenced from inside liquid files using a relative URL and the assets_url filter. This URL get's swapped for the correct URL on build. e.g.:

<style>
    @font-face {
      font-family: REZ;
      src: url({{ '../assets/fonts/REZ.ttf' | asset_url }}) format('truetype');
      font-style: normal;
      font-weight:  700;
    }
</style>

changes to

<style>
    @font-face {
      font-family: REZ;
      src: url({{ 'REZ.ttf' | asset_url }}) format('truetype');
      font-style: normal;
      font-weight:  700;
    }
</style>

Going to create a few followup issues about what I've talked about here.

@t-kelly
Copy link
Contributor

t-kelly commented Feb 22, 2018

Closing this in preference of the two issues I made above. Feel free to continue the conversation here if need be.

@t-kelly t-kelly closed this as completed Feb 22, 2018
@schellenbergk
Copy link

assert_url -> asset_url?

@t-kelly
Copy link
Contributor

t-kelly commented Feb 28, 2018

@schellenbergk yes! Sorry typo :)

@rg-najera
Copy link

rg-najera commented Mar 28, 2018

@t-kelly I see this is closed but I think further clarification is needed in the README regarding images.

When using asset_url as described above like so:

<img src="{{ '../assets/images/home/some_image.png' | asset_url }}"/>

The result while in dev adds the cdn path and adds the full path of the local image including the local domain:

<img src="//cdn.shopify.com/s/files/1/2643/4686/t/2/assets/https://localhost:8080/some_image.png?2881255340471558967">

Makes sense since what is being parsed out by webpack results in the following:

<img src="{{ 'https://localhost:8080/some_image.png' | asset_url }}"/>

if this is whats intended, I might just not be getting it.

Would be totally natural for webpack to instead strip the liquid tags completely and instead include only the src url since https://localhost:8080/some_image.png is available on request.

Note, when building, it seems to work fine though and it includes the striped out version of the liquid tag without a relative path.

@t-kelly
Copy link
Contributor

t-kelly commented Mar 28, 2018

@el-rotny can you please create a new issue for this, since it is unrelated to the title of this issue. Thanks.

@lock
Copy link

lock bot commented Oct 26, 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 Oct 26, 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

4 participants