-
Notifications
You must be signed in to change notification settings - Fork 15
document how to setup a sprite loader for use with svg-store #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lastobelus
wants to merge
2
commits into
DynamoMTL:master
Choose a base branch
from
lastobelus:docs/svg-sprite-loader
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ So excited you wanna get started right away? [Boom](#getting-started) | |
|
|
||
| **JS Unit Testing**: We added a default unit testing setup, using Jest, so that you don't have to. You can jump to [the testing section](#8-specs) to learn more about this. | ||
|
|
||
| **Pipeline Customization and Augmentation**: We are providing you with base Webpack configs for the development and production environments, but you can extend them to add your own specific solutions to the pipeline. More on this here [link]. | ||
| **Pipeline Customization and Augmentation**: We are providing you with base Webpack configs for the development and production environments, but you can extend them to add your own specific solutions to the pipeline. More on this here [link]. | ||
|
|
||
| **Multiple Environment Support**: Shopify Pipeline uses a YAML file similar to [Theme Kit's `config.yml`](https://shopify.github.io/themekit/configuration/) file to allow you to have different credentials for your development and production environments. | ||
|
|
||
|
|
@@ -110,27 +110,27 @@ Once Shopify Pipeline has created the scaffolding of your project, it will have | |
| #### [0] Packages | ||
|
|
||
| `package.json` | ||
|
|
||
| The package file will be generated for you by Shopify Pipeline upon project creation. | ||
|
|
||
| We are so nice that we will also generate npm/yarn scripts for you to be able to use Shopify Pipeline's CLI easily from the terminal (e.g. `yarn serve`). | ||
|
|
||
| #### [1] ESlint Config | ||
|
|
||
| `.eslintrc` (optional) | ||
|
|
||
| If you add a ESlint config file on the root of your app, Shopify Pipeline will use that file for the eslint-loader. | ||
|
|
||
| #### [2] Shopify Config | ||
|
|
||
| `config/shopify.yml` | ||
|
|
||
| Shopify Pipeline will use this config file to setup the development and production flow. It is mimicking what is already being used by [Theme Kit](https://shopify.github.io/themekit/configuration/) and will work accordingly. | ||
|
|
||
| #### [3] Webpack Config | ||
|
|
||
| `config/webpack.[dev|prod].conf.js` | ||
|
|
||
| If Shopify Pipeline finds one or both of those files in the `config` folder, it will merge them with the default Webpack config files everytime you start the webpack-dev-server or that you build your project. This allows you to add loaders and plugins to augment the base toolset provided to you by Shopify Pipeline. | ||
|
|
||
| We are using [webpack-merge](https://www.npmjs.com/package/webpack-merge) to elegantly achieve this goal. | ||
|
|
@@ -140,7 +140,7 @@ Of course, with great power comes great responsibility: please use this feature | |
| #### [4] JS Files | ||
|
|
||
| `src/assets/js` | ||
|
|
||
| This folder will contain all your JS modules. An `index.js` must be present, as it will act as the entry point for your JS application. | ||
|
|
||
| You can use ES6/ES2015's standard, which incidently allows you to require your modules with the `import` syntax: | ||
|
|
@@ -153,7 +153,7 @@ import Foo from './modules/foo' | |
| #### [5] Sass and CSS Files | ||
|
|
||
| `src/assets/sass` | ||
|
|
||
| Shopify Pipeline fully supports `.css`, `.scss` and `.sass` files and their syntax, including `@import`. | ||
|
|
||
| You **must** include your style index file at the top of your `index.js` file for Webpack to be able to load your styles into its build process, as such: | ||
|
|
@@ -169,24 +169,37 @@ If you intend to use [Stylelint support](#roadmap) (coming soon!), also note tha | |
| #### [6] SVG Store | ||
|
|
||
| `src/assets/svg` | ||
|
|
||
| If you want to use the [SVG Store technique](https://css-tricks.com/svg-sprites-use-better-icon-fonts/), we added its support out of the box with the help of [webpack-svgstore-plugin](https://github.com/mrsum/webpack-svgstore-plugin). | ||
|
|
||
| Here are the steps necessary to use it: | ||
| Here are the steps necessary to use it: | ||
| 1. Place all the necessary Svg files inside the `svg` folder | ||
| 2. Somewhere in your JS application, you need to create this variable and assignment: | ||
| ``` | ||
| var __svg__ = { path: '../svg/**/*.svg', name: 'logos.svg' }; | ||
| ``` | ||
| ``` | ||
| This will tell the SVG Store plugin [that it needs to generate the sprite file](https://github.com/mrsum/webpack-svgstore-plugin#2-put-function-mark-at-your-chunk). | ||
|
|
||
| **Note** that the plugin will add a `icon-` prefix to your file name as the `id` of the symbol in the sprite. There is no way to change this at the moment. Given that this is less than an ideal integration, we will look for better ways to generate the store [in the future](#roadmap). | ||
|
|
||
| Also **note** that, if you want to reference the sprite file in your liquid templates, [you will need to make sure that the url is not parsed by Webpack](#how-to-prevent-webpack-from-parsing-some-liquid-methods-and-filters). You can do so by wrapping the liquid curly brackets in a single quote and the name of the sprite in double quotes, like so: | ||
| ``` | ||
| <div data-some-attribute='{{ "logos.svg" | asset_url }}'></div> | ||
| <div data-svgloader='{{ "logos.svg" | asset_url }}'></div> | ||
| ``` | ||
|
|
||
| The sprite loader that comes with [webpack-svgstore-plugin]((https://github.com/mrsum/webpack-svgstore-plugin) won't work out of the box, instead given that you have included the above liquid snippet in your theme, this loader will suffice: | ||
| ``` | ||
| $('[data-svg-loader]').each(function _loadSvg() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like for this example not to use jQuery, as we do not include it ourselves. Maybe using the fetch API ? Also, I think the example should follow the Dyanmo's ESLint config - so for example, functions shouldn't start with an underscore. |
||
| const $this = $(this) | ||
| $.get($this.data('src'), (svg) => { | ||
| const svgSerialized = new window.XMLSerializer().serializeToString(svg.documentElement) | ||
| this.innerHTML = svgSerialized | ||
| }) | ||
| }) | ||
| ``` | ||
|
|
||
| **Updating SVGs:** To get the svg store to regenerate, you must touch `index.js` -- editing, adding/removing svgs will not trigger a recompile. | ||
|
|
||
| #### [7] Shopify Required | ||
|
|
||
| `src/config`, `src/layout/theme.liquid`, `src/locales`, `src/sections`, `src/snippets`, `src/templates/*.liquid` | ||
|
|
@@ -226,7 +239,7 @@ To have access to Shopify Pipeline's CLI commands, you then have two options: | |
| xxx: 'shopify-pipeline command', | ||
| ... | ||
| } | ||
|
|
||
| // In the terminal: | ||
| // yarn xxx --someflag | ||
| ``` | ||
|
|
@@ -293,7 +306,7 @@ We would like to specifically thank the following projects, for the inspiration | |
| - [Shopify](https://github.com/Shopify), [Themekit](https://github.com/Shopify/node-themekit) and [Slate](https://shopify.github.io/slate/) | ||
|
|
||
| ## Made by Dynamo | ||
| This tool was created with love by [Dynamo](http://godynamo.com/), a Montreal-based full-service digital design studio. | ||
| This tool was created with love by [Dynamo](http://godynamo.com/), a Montreal-based full-service digital design studio. | ||
|
|
||
| The goal behind Shopify Pipeline is to alleviate some of the downsides of working within the Shopify ecosystem and bring forward some of the nice features you get when building custom e-commerce websites outside of it. | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have an extra opening parenthesis in the
webpack-svgstore-pluginlink.I think we should advocate for writing (and importing) a module instead of putting code directly in a liquid template.