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

Reduce code duplication across projects with Web Components #336

Open
t-kelly opened this issue Nov 6, 2017 · 1 comment
Open

Reduce code duplication across projects with Web Components #336

t-kelly opened this issue Nov 6, 2017 · 1 comment

Comments

@t-kelly
Copy link
Contributor

t-kelly commented Nov 6, 2017

The Shopify themes team has the problem of maintaining 10+ different free themes all with their own unique codebase. Whenever we need to apply an update to our themes, we need to 10+ times. Even worse, each update needs to be customized to each theme because themes development has changed over the past 4 years that they've all been created.

What if teams could develop and share self-incapsulated components that could be configured and used if a variety of themes. So instead of maintaining 10+ different implementations of a hero slider, we only need to maintain 1 implementation.

Essentially what we need are Web Components.

Random Idea 1

One idea to get started is to combine {% import %} tags and WebPack to take advantage of sharing snippets (components) through NPM:

<!-- /sections/hello-world.liquid -->
<div id="{{ section.id }}">
  {% import '@ShopifyComponents/hello`, 
     name: section.settings.name, 
     color: section.settings.color 
   %}
</div>
<!-- /node_modules/@ShopifyComponents/hello/hello.liquid -->
<h1>Hello, {{ name }}!</h1>

<style>
h1 {
  color: {{ color }}
}
</style>

WebPack could parse {% import %} tags URL, copy the files referenced to the /snippets directory, and change the {% import %} URL to reference the newly created snippet. Eg:

{% import '@ShopifyComponents/hello` %}

would be compiled to

{% import 'hello` %}

So far this is only a partial implementation of something that kind of resembles Web Components. Would love to hear from the community on any ideas how to approach this problem!

@t-kelly t-kelly added this to the 1.0.0 milestone Nov 6, 2017
@t-kelly t-kelly added the !! label Nov 7, 2017
@t-kelly t-kelly changed the title Import components for reduced code duplication across projects Web components for reduced code duplication across projects Nov 7, 2017
@t-kelly t-kelly changed the title Web components for reduced code duplication across projects Reduce code duplication across projects with Web Components Nov 7, 2017
@t-kelly t-kelly removed this from the 1.0.0 milestone Jan 9, 2018
@t-kelly t-kelly added v1.x and removed !! labels Feb 21, 2018
@taivu
Copy link

taivu commented Feb 4, 2020

this idea sounds and feels like Pattern Lab (https://patternlab.io/).

Drupal uses Twig, which looks similar to Liquid. When I worked with it, i did things like the code examples you shared, like:

{% include @scope/thing %}

where @scope gets mapped to a specific folder. Maybe theres some concepts from Pattern Lab that could influence or inspire some solutions to Shopify Theming.

edit: https://github.com/EvanLovely/plugin-twig-namespaces name spaces is what does the scope thing live above examples.

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

2 participants