Modern Shopify Themes Development with Nx-Shopify
Tags: showdev, webdev, typescript, shopify
Published: 2021-05-14 14:03:18

# TL;DR 

Nx-Shopify is an [Nx](https://nx.dev) plugin for developing Shopify themes with performance, modern tooling, and ergonomics in mind.

Check the Getting Started guide and the full docs at the [Nx-Shopify](https://trafilea.github.io/nx-shopify/) official website.

{% github trafilea/nx-shopify %}

# A little history: Shopify Slate & Themekit

Before being [deprecated in January 2020](https://github.com/Shopify/slate/pull/1091), Shopify's official toolkit for developing Shopify themes was [Slate](https://github.com/Shopify/slate). Slate provided a theme development environment that enabled the developer to have a better project structure than the regular directories found in a Shopify theme. With the deprecation of Slate, the only official tool for theme development left is [Themekit](https://shopify.dev/tools/theme-kit).

Themekit acts like a bridge between the developer's local files and the files found in a Shopify store's theme. The folder structure of a Themekit theme is meant more for the theme rendering process than for code maintainability or multiple developers constantly working on the same code base. Additionally, a Themekit project provides little to zero build tooling for the application code. 

This is how a basic Themekit project looks like:

![Themekit Structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zd9i6v38g40jnm5x1ep.png)

Given the context above, the need to have a well-defined project structure, dev ergonomics, high-quality code, and use of modern web technologies, were limited due to lack of tooling.

At [Trafilea](https://trafilea.com), we heavily use Shopify themes and are constantly making changes to them according to our business needs and growth. Providing our developers a functional, stable, and feature-rich development experience is crucial, this why we built and open-sourced [Nx-Shopify](https://github.com/trafilea/nx-shopify).

# Nx-Shopify 🚀

Nx-Shopify is an Nx plugin that adds support for modern Shopify Themes development to an Nx workspace. It comes with various features including:

- TypeScript based.
- Styling with SASS and PostCSS.
- Out of the box unit testing with Jest.
- Out of the box code formatting using Prettier and ESLint.
- Multiple application and Themekit environments.
- Code lazy loading.
- Code generator for creating new themes with separate configs.
- Code generators for creating theme blocks such as layouts, templates, sections, and snippets.
- React integration via `@nrwl/react`.
- Webpack extended configuration.
- ➕ all features included in an Nx workspace.

Nx-Shopify makes use of Shopify Themekit under the hood, so every project built with Nx-Shopify will be compliant with the themekit project format, in case you need to run specific themekit commands in your project. **TIP:** you can add custom targets for your projects using the [Nx run commands executor](http://nx.dev/workspace/run-commands-executor).

Ok, but...

## What is Nx?

Nx is a set of dev tools for monorepos designed to provide a great development experience in a plug-and-play way. According to their website: "**Nx** is a suite of powerful, extensible dev tools to help you architect, test, and build at any scale — integrating seamlessly with modern technologies and libraries while providing a robust CLI, caching, dependency management, and more."

Watch this 35 seconds video to have a general overview of some of the things Nx does:

{% youtube BIeQTWLyAqc %}

(We ❤️ Nx)

## Code Generators

Most Nx plugins include code generators to facilitate developers' life so they can focus on what really matters. Nx-Shopify includes generators for:

- [New themes](https://trafilea.github.io/nx-shopify/docs/fundamentals/creating-a-theme)
- [Layouts](https://trafilea.github.io/nx-shopify/docs/cli-usage/generators/layout)
- [Templates](https://trafilea.github.io/nx-shopify/docs/cli-usage/generators/template)
- [Sections](https://trafilea.github.io/nx-shopify/docs/cli-usage/generators/section)
- [Snippets](https://trafilea.github.io/nx-shopify/docs/cli-usage/generators/snippet)

A fresh generated Shopify theme would look like this:

![Nx-Shopify Structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnm046v355dupw99pdh5.png)

Every theme block is organized in a component-based/cohesive design with its respective Liquid, styles, Typescript, and test files. You can also nest blocks under another block's directory if that makes sense to you. You have control of your theme project architecture. 

## CLI commands

The CLI commands that can be executed against a theme are known in Nx as executors. The list of executors included with Nx-Shopify are:

- [build](https://trafilea.github.io/nx-shopify/docs/cli-usage/executors/build) - Builds the theme to a Themekit compliant structure ready to be deployed to Shopify
- [serve](https://trafilea.github.io/nx-shopify/docs/cli-usage/executors/serve) - Runs a local web & assets server for local theme development
- [test](https://trafilea.github.io/nx-shopify/docs/cli-usage/executors/test) - Runs Jest tests against the theme code.
- [deploy](https://trafilea.github.io/nx-shopify/docs/cli-usage/executors/deploy) - Deploys a built theme to Shopify according to the Themekit environment configured in the `config.yml` file

You get a list of all plugin's generators and executors by running the following command in your workspace:

```bash
nx list @trafilea/nx-shopify
```

## React integration via `@nrwl/react`

Do not miss the [React integration step-by-step guide](https://trafilea.github.io/nx-shopify/docs/guides/using-react) on our docs site.

----

Star ⭐ the repo, check the [docs](https://trafilea.github.io/nx-shopify/), and power up your Shopify themes development experience!

{% github trafilea/nx-shopify %}