npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-shopify-liquid-script

v1.0.0

Published

A Rollup plugin that generates Liquid templates for importing JavaScript files, with support for Shopify Liquid and custom SystemJS import mapping.

Downloads

2

Readme

Shopify Liquid Import Scripts Plugin for Rollup

A Rollup plugin that generates Liquid templates for importing JavaScript files, with support for Shopify Liquid and custom SystemJS import mapping.

Features

  • Generates Liquid templates to import JavaScript files into your Shopify store.
  • Configures SystemJS import mappings for use with Shopify Liquid.
  • Allows customization of the assets directory and Liquid template directory.

Installation

To install the plugin, use npm, yarn, or pnpm:

npm install --save-dev rollup-plugin-shopify-liquid-script

or

yarn add --dev rollup-plugin-shopify-liquid-script

or

pnpm add --save-dev rollup-plugin-shopify-liquid-script

Usage

In your rollup.config.js, include the plugin in the plugins array and specify your options as needed:

import { defineConfig } from 'rollup';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { globSync } from 'glob';
import shopifyLiquidScript from 'rollup-plugin-shopify-liquid-script';

const entryPoints = globSync("./src/entrypoints/**/*");

export default defineConfig({
  input: entryPoints,
  output: {
    dir: "assets",
    format: "system", // Ensure the format is set to 'system'
    manualChunks: {
      stencil: ["@stencil/core"],
    },
  },
  treeshake: true,
  plugins: [
    resolve({ extensions: [".mjs", ".js", ".json", ".node", ".tsx", ".ts"] }),
    commonjs(),
    shopifyLiquidScript(),
  ],
});

Important Notes

  • Output Format: The Rollup output format must be set to 'system'. This is necessary to ensure that the generated Liquid templates correctly map the SystemJS imports for use in Shopify.

  • SystemJS Loader: The generated Liquid templates require SystemJS to load the JavaScript modules. Include the following script tag in your Shopify theme:

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/system.min.js"></script>

Options

The plugin accepts the following options:

export type Options = {
  /**
   * The directory path where assets are located. Usually this should be 'assets'.
   * @default 'assets'
   */
  assetsDir?: string;

  /**
   * The directory path where Liquid files should be generated. Usually this should be 'snippets'.
   * @default 'snippets'
   */
  liquidDir?: string;
};
  • assetsDir: Specifies the directory where the generated assets will be placed. By default, this is set to "assets".
  • liquidDir: Specifies the directory where the Liquid templates will be generated. By default, this is set to "sections".

Output Example

The generated Liquid section files will include SystemJS configuration in the following format:

<script>SystemJS.config({"map":{"./entry-1.js":"{{ 'entry-1.js' | asset_url }}","./stencil-BcHQo1kZ.js":"{{ 'stencil-BcHQo1kZ.js' | asset_url }}","./module-1-Ctc87KA9.js":"{{ 'module-1-Ctc87KA9.js' | asset_url }}"}})</script>
<script src='{{ 'entry-1.js' | asset_url }}}'></script>

This output ensures that your JavaScript files are correctly imported and mapped using SystemJS in your Shopify store.

Example

Here is an updated example configuration in rollup.config.js:

import { defineConfig } from 'rollup';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { globSync } from 'glob';
import shopifyLiquidScript from 'rollup-plugin-shopify-liquid-script';

const entryPoints = globSync("./src/entrypoints/**/*");

export default defineConfig({
  input: entryPoints,
  output: {
    dir: "assets",
    format: "system",
    manualChunks: {
      stencil: ["@stencil/core"],
    },
  },
  treeshake: true,
  plugins: [
    resolve({ extensions: [".mjs", ".js", ".json", ".node", ".tsx", ".ts"] }),
    commonjs(),
    shopifyLiquidScript({
      assetsDir: "assets",
      liquidDir: 'snippets',
    }),
  ],
});

In this example:

  • The assets will be output to the "assets" directory.
  • The Liquid templates will be generated in the "snippets" directory.
  • The output format is set to 'system' to ensure compatibility with SystemJS.
  • The manualChunks option is used to separate @stencil/core into its own chunk.

License

This project is licensed under the MIT License. See the LICENSE file for details.