Giter Site home page Giter Site logo

wenfw / ebytwo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jsmithseo/ebytwo

0.0 0.0 0.0 44.34 MB

Home Page: eby-two.vercel.app

License: MIT License

Shell 0.07% JavaScript 91.92% Ruby 0.01% C++ 1.48% Python 1.27% Perl 0.01% C 0.03% PHP 0.01% Emacs Lisp 0.01% CoffeeScript 0.03% C# 0.01% TypeScript 1.39% CSS 0.15% Nix 0.01% Makefile 0.03% HTML 0.96% Liquid 2.64% Batchfile 0.01% HCL 0.01% M4 0.01%

ebytwo's Introduction

Shopify ThemeKit with Webpack 5

This is a starter Theme using Webpack, ThemeKit and TailwindCSS for developing Shopify themes with modern build tools. The goal is to create a tool with a component-based folder structure and is easy to use.

πŸ“ Folder Structure

This is set up for a component-based file structure. All liquid, js and scss are in the same folder to keep things in one place. Example of folder structure:

  • components
    • sections
      • header
        • header.js
        • header.liquid
        • header.scss

Note: always import component scss files into the component javascript file. For example import './header.scss'; is inside header.js. This ensures the scss will get compiled to css with Webpack. There are some rules to follow with this folder structure. For each component liquid file use the following template.

<style></style>
<html></html>
<script></script>

It's important to reference styles and scripts from the compiles assets folder. Webpack will compile all js and css files under the filename. For example a starting template for a header.liquid component would look like this.

<!-- Reference to compiled style in assets folder -->
{{ 'bundle.header.css' | asset_url | stylesheet_tag }}

<div class="header_container">
    <!-- HTML HERE -->
</div>

<!-- Reference to compiled js in assets folder -->
{{ 'bundle.header.js' | asset_url | script_tag }}

Note: The scss or css file can alternatively be imported into the js file which will get compiled with webpack.

Node Version Manager

This theme setup is built with Yarn, Webpack and ThemeKit which are dependant on NodeJS versions. You can use node v14 to install dependencies and run build commands.

  • Install nvm
  • Run nvm install v14 in terminal
  • Install dependencies yarn install

Clean-CSS CLI

This project uses clean-css-cli to minify TailwindCSS during build.

Install Clean-CSS CLI
yarn add clean-css-cli -g
Note: Global install via -g option is recommended unless you want to execute the binary via a relative path, i.e. ./node_modules/.bin/cleancss

TailwindCSS

This project uses TailwindCSS v2 a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup. Checkout the amazing documentation and start adding classes to your elements.

Getting Started

  • Install dependencies yarn install or npm i
  • Rename the config.yml.example to config.yml and add the Shopify Theme credentials
  • Run a build test yarn build if no errors then you are good to go

Note: the first time you run yarn start or yarn deploy to a new theme you must comment out ignore_files.

# - config/settings_data.json
# - "*.js"
# - "*.hot-update.json"

Webpack Dev Server

  • yarn start will run build commands and start the webpack development server.
  • yarn build will run build commands and create a dist folder of the compiled files.
  • yarn deploy will upload the dist folder contents to your theme configured in the yml

Self-Signed Certificate

In the event that you find the HMR assets are not loading and the requests to localhost:9000 are 404 you will need to approve or pass a valid certificate. To solve this issue you can open a new browser window and approve the SSL Certificate or pass a valid certificate as mentioned here devServer.https.

HMR (Hot Module Reloading)

When in development mode yarn start hot module reloading is enabled. It watches for changes to JavaScript, CSS and Liquid files. When JS or CSS is changes the browser will change without the need to refresh. When changes are made to liquid files a manual browser reload may be required.

Whitespace control

In Liquid, you can include a hyphen in your tag syntax {{-, -}}, {%-, and -%} to strip whitespace from the left or right side of a rendered tag. By including hyphens in your assign tag, you can strip the generated whitespace from the rendered template. If you don’t want any of your tags to print whitespace, as a general rule you can add hyphens to both sides of all your tags ({%- and -%}):

{%- assign username = "Borat Margaret Sagdiyev" -%}
{%- if username and username.size > 10 -%}
  Wow, {{ username }}, I like!
{%- else -%}
  Hello there!
{%- endif -%}

Variable Scope & Components

This is not unique to this project but it's worth mentioning and creating a component example. See the src/components/snippets/dynamic-modal/dynamic-modal.liquid component. This is a simple modal that uses variable scope for data, styles and functions. In this file we assign some default variables.

{%- assign id = "defaultModal" -%}
{%- assign openModalBtn = "defaultOpenButton" -%}
{%- assign title = "Modal Title" -%}
{%- assign body = "Modal Body" -%}

Use this dynamic-modal.liquid component by creating a trigger element like a button with an id.

<button id="testButton">Trigger Modal</button>

Next we include the modal in a section with declared variables. These will be scoped to the snippet and we now have a dynamic reusable modal component we can use throughout our theme.

{%- include "dynamic-modal", 
    id: "homePageTestModal",
    openModalBtn: "testButton",
    title: "Testing Title Variable",
    body: "Testing the Dynamic Body Of the Modal...",
    buttonOne: "Alert",
    buttonOneFunction: "alert('Q: Do you struggle with impostor syndrome? Me: no I’m great at it')"
    buttonTwo: "Close",
    buttonTwoStyle: "text-white bg-red-500 hover:bg-red-700"
    buttonTwoFunction: "modal.style.display = 'none';"
-%}

Read more on this Shopify Variable Scopes. If you find some good use cases for these please post them in the discussion ideas category

EbyTwo

ebytwo's People

Contributors

3daddict avatar felixmosh avatar jsmithseo avatar mvuljevas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.