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

@plugdigital/shopify-theme-build-tools

v1.0.7

Published

Tools for organizing, processing, and packaging JS and CSS/SCSS files for use in Shopify themes.

Downloads

1

Readme

Plug Shopify Theme Tools

How to Use

  1. Required project directory structure:
    • Project
      • theme
      • scripts (optional, can be named whatever you like)
      • styles (optional, can be named whatever you like)
    • Note, if only the theme directory is present, this application will do nothing.
  2. Navigate to Project directory.
  3. $ npm init
  4. $ npm i @plugdigital/shopify-theme-build-tools
  5. Create the run.js file, adding it to the Project directory (see example below).

Example Run File

import pathTools from "path";
import { fileURLToPath } from "url";
import start from "@plugdigital/shopify-theme-build-tools";
import TerserPlugin from "terser-webpack-plugin";

// The __dirname node global variable is not available in modules,
// which is why we have to do it this way.

const __filename = fileURLToPath(import.meta.url);
const __dirname = pathTools.dirname(__filename);

// The 'scripts' and 'stylesheets' paths are optional, however if BOTH
// are missing, then the app does nothing. So you should always have at
// least one or the other, when using this app.

const paths = {
    base: __dirname, // required
    themeAssets: pathTools.join(__dirname, "theme", "assets"), // required
    scripts:  pathTools.join(__dirname, "scripts"),
    stylesheets: pathTools.join(__dirname, "styles"),
};

const jsMinificationSettings = {
    minimizer: [
        new TerserPlugin({
            parallel: true,
            extractComments: true,
            terserOptions: {

// When true, this option changes the code to make it more terse.

                compress: false,

// When true, this option mangles the variable and function names.  

                mangle: false,
            }
        })
    ]
};


// Start watching files.

start({
    paths,
    scriptSettings: {

// You can use any webpack configuration that you like, and since webpack
// is well documented, it is easy to find information about how to
// customize your config to suit your needs.

// We implement the file watching ourselves, so the 'entry' property is
// required on every config object so that we can determine the
// appropriate config to use when a JS file we are watching changes.

        webpackConfigs: [

// When you want to package a module into a single file, you can use a
// config object like the following. The 'entry' property specifies the
// path to the module that we want to package. When any file in that
// directory changes, webpack will look for an 'index.js' file, and
// package it along with all of its dependencies into a single file.

            {
                mode: "production",
                entry: pathTools.join(paths.scripts, "base"),
                output: {
                    path: paths.themeAssets,
                    filename: "plug-base.js"
                },
                optimization: jsMinificationSettings
            }
        ],

// Optional, a function which will be called every time a JS file is
// changed which has no configuration specified in 'webpackConfigs'.
// If this function is undefined, and a file has no configuration
// specified in 'webpackConfigs', then that file will be ignored.

        createSingleFileWebpackConfig: function (inputPath) {
            const parsedInputPath = pathTools.parse(inputPath);
            const inputFilename = parsedInputPath.base;
            return {
                mode: "production",
                entry: inputPath,
                output: {
                    path: paths.themeAssets,
                    filename: inputFilename
                },
                optimization: jsMinificationSettings
            };
        }
    },
    stylesheetSettings: {

// Shopify minifies and caches all CSS files now, so this is not necessary
// unless you need to remove comments or something.

        minify: false
    }
});

Example Project Structure

Note, the scripts and stylesheets below

  • theme
    • assets
    • config
    • layout
    • locales
    • sections
    • snippets
    • templates
  • scripts
    • base   <-- This module will be packaged into a single file.
      • globalComponents
        • header.js
        • footer.js
        • cartDrawer.js
      • events.js
      • utils.js
      • index.js   <-- This file is the entry point for the 'base' module.
    • mobile-nav.js
    • cart.js
    • ...
  • styles
    • plug-base
      • _buttons.scss
      • _forms.scss
      • plug-base.scss
    • component-mobile-nav.css
    • section-blog-post-main.scss
    • section-header.scss
    • ...

Stylesheets

  • The stylesheets must be .scss files. We can add support for Less or other preprocessing 'languages' as needed.

  • When stylesheets whose filename starts with an underscore are changed, it triggers the compilation and minification of the first file in their directory which is not prefaced with an underscore. All other stylesheets are compiled and minified individually, and copied to theme/assets/.

Recommended Usage

  • SCSS files should be compiled to CSS but not minified. This is because Shopify minifies CSS files and caches the result the first time they are requested.

  • For JS files, we do minify them (until we can confirm that Shopify automatically minifies them), but we ONLY REMOVE WHITESPACE AND COMMENTS. Anything that rewrites the JS in a more terse manner should be avoided. This ensures that JS is easy to debug in the browser without having to upload sourcemaps too. For anyone needing to read a minified script, sites like unminify.com will make it legible, and again, since we aren't modifying the code itself, any unminifier tool should output readable code.