@cactuslab/shopify-file-loader

0.0.7 • Public • Published

Shopify file loader for webpack

Based on webpack's file-loader to support Shopify's liquid URL filters.

Installation

npm install shopify-file-loader --save-dev

Usage

The loader follows the same configuration as the original file-loader, meaning that all options from the original loader are supported such as the filename templates.

However, it is important to allow the query string when testing for filenames (notice the (\?.*)? below?).

  module: {
    loaders: [
      ...,
      { // Theme Assets
        test: /\/assets\/(.+?)\.(jpe?g|gif|png|woff|woff2|eot|ttf|svg)(\?.*)?$/,
        loader: 'shopify-file?name=assets/[name]-[hash].[ext]'
      }
    ]
  }

The following CSS

#foo {
    background-image: url(src/assets/images/bg.png);
}

Emits bg.png as assets/bg-0dcbbaa701328a3c262cfd45869e351f.png in the output directory and returns the liquid tag:

#foo {
    background-image: url({{'bg-3a6f8fc07427621158d3d78d92e20f23.png' | asset_url}});
}

Now the CSS file (with .css.liquid extension) will include the correct assets URLs.

Filter parameters

The asset_url URL filter is used by default. Other filters can be used as such:

#foo {
    background-image: url(src/assets/images/bg.png?asset_img_url=300x);
    /* emits -> url({{'bg-3a6f8fc07427621158d3d78d92e20f23.png' | asset_img_url: '300x'}}) */

    background-image: url(src/assets/images/bg.png?asset_img_url=300x&crop=bottom);
    /* emits -> url({{'bg-3a6f8fc07427621158d3d78d92e20f23.png' | asset_img_url: '300x', crop: 'bottom'}}) */
}

Readme

Keywords

none

Package Sidebar

Install

npm i @cactuslab/shopify-file-loader

Weekly Downloads

1

Version

0.0.7

License

MIT

Unpacked Size

4.51 kB

Total Files

3

Last publish

Collaborators

  • hydnhntr
  • karlvr
  • tomcarey