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

@alexander.k/vite-plugin-for-shopify

v1.1.1

Published

Vite plugin for generate snippet with all inputs (entries).

Downloads

149

Readme

Vite plugin for generate snippet with all inputs (entries).

Usage

Add the plugin to your vite.config.js

All options are not required:

import shopifyVitePlugin from '@alexander.k/vite-plugin-for-shopify'

export default {
  plugins: [
    shopifyVitePlugin({
      // root path to theme, default value is './'
      themeRoot: './',
      // snippet you will use in the liquid, default value is 'vite.liquid'
      snippetFilename: 'vite.liquid',
      cleanup: {
        // regex for filtering files in the assets folder that are generated during assembly,
        // needed to remove files from previous assemblies,
        // for example if files are created with a hash in the name
        // there is no default value, old files will not be deleted
        fileNameRegex: /.*\.min\.(js|css)$/m
      }
    })
  ]
}

Add snippet to <head></head> without params once

it will add the helper function for dynamic import in your code for example, to the theme.liquid file

<html>
  <head>
    ...
    {% render 'vite' %}
  </head>
  <body>
    ...
  </body>
</html>

Use snippet with entryName as in inputs, for example:

inputs in the vite.config.js

export default defineConfig({
  plugins: [
    shopifyVitePlugin()
  ],
  build: {
    rollupOptions: {
      input: {
        theme: './some-path/theme.js',
        coolSection: './some-path/collSection.js',
        utils: './some-path/utils.js',
        pageStyles: './some-path/pageStyles.css'
      }
    }
  }
})

default

{% liquid
  # it can also preload styles
  render 'vite', entry: 'theme', preload_stylesheet: true
  render 'vite', entry: 'pageStyles'
  render 'vite', entry: 'coolSection'
%}

only styles or only js

{% liquid
  # only style
  render 'vite', entry: 'theme', only_css: true
  # only js
  render 'vite', entry: 'coolSection', only_js: true
%}

import mode for styles

<template class="component-template">
  <style>
    {% render 'vite', entry: 'theme', only_css: true, import_mode: true %}
    :root {
      display: block;
    }
    .wrapper {
      padding: 10px;
    }
  </style>
  <div class="wrapper">
    <button class="global-class-from-theme">Button</button>
  </div>
</template>

==> result:

<template class="component-template">
  <style>
    @import url("//www.your-store.com/cdn/shop/t/111/assets/theme.C0CJB5x1.min.css");
    :root {
      display: block;
    }
    .wrapper {
      padding: 10px;
    }
  </style>
  <div class="wrapper">
    <button class="global-class-from-theme">Button</button>
  </div>
</template>

import mode for js

<script type="module">
  {% render 'vite', entry: 'utils', only_js: true, import_mode: true, import_name: '{ getCart }' %}

  const cart = getCart()
</script>

==> result:

<script type="module">
  import { getCart } from "//www.your-store.com/cdn/shop/t/111/assets/utils.C0CJB5x1.min.js";

  const cart = getCart()
</script>

or dynamic way

<script type="module">
  const addClickHandler = async (items) => {
    {% render 'vite', entry: 'utils', only_js: true, import_mode: true, dynamic_import: true, import_name: '{ addToCart }' %}

    return await addToCart(items)
  }
</script>

==> result:

<script type="module">
  const addClickHandler = async (items) => {
    const { addToCart } = await import("//www.your-store.com/cdn/shop/t/111/assets/utils.C0CJB5x1.min.js");

    return await addToCart(items)
  }
</script>