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

gatsby-plugin-asset-path

v3.0.4

Published

Gatsby plugin that copies JS and CSS files and static folder to a custom folder

Downloads

20,123

Readme

gatsby-plugin-asset-path

Copy all of your JS and CSS build files, as well as the static folder into a subdirectory of your choice.

Breaking change in v3

No longer moves files due to gatsby's internal cache management. Copying files instead!

Breaking change in v2

  • A sitemap is no longer required
  • A webmanifest is no longer required

The above two files were hard coded into this plugin in earlier versions. If you still want to move these files to the assets folder, use the new paths option, see below for more information on the option. To get the same behavior as v1, use the following options:

options: {
  paths: ["manifest.webmanifest", "sitemap.xml"],
},

Also note that sitemap.xml and the page-data folder were copied to assets folder before, now they are moved just as all other files this plugin handles.

Breaking change in v1

Use assetPrefix instead of pathPrefix

Our use case

Gatsby by default will generate all of the assets and put them directly at the root level:

public
│   index.html
│   component1.js
|   component1.js.map
|   component1.css
|   component2.js
|   compoennt2.js.map
|   component3.css
└───path1
│   │   index.html
│   │   other1.html
│───path2
│   │   index.html
│   │   other2.html
|___static
|   |   data.json
|   |   image.jpg

However here at MadeComfy, we host our site on AWS Cloudfront/S3. One issue that we faced was that somehow, two different builds would have some JS/CSS files with the same file names even though their content are different.

That means during deployment on S3 and object invalidation on Cloudfront, someone that is currently browsing the site, would see the experience broken whilst moving onto other pages as the loaded JS would still have asset references of the previous build.

Hence our need to make sure that each build is kept intact on Cloudfront, except the HTML that are loaded on the browser at each hard reload. That way we make sure that our site has no down time at any point of time. We've configured our caching configs this way.

Using this plugin, our file struture is now as followed:

public
│   index.html
|___assets
|   |___1534761288
│   |   |   component1.js
│   |   |   component1.js.map
│   |   |   component1.css
│   |   |   component2.js
│   |   |   compoennt2.js.map
│   |   |   component3.css
│   |   |___static
│   |   |   |   data.json
│   |   |   |   image.jpg
└───path1
│   │   index.html
│   │   other1.html
│───path2
│   │   index.html
│   │   other2.html

Our new assets folder would contain assets of every build once on S3.

Install

npm install --save-dev gatsby-plugin-asset-path
yarn install -D gatsby-plugin-asset-path

How to use

// Your gatsby-config.js
{
    assetPrefix: "custom_asset_folder",
    plugins: [
        {
            resolve: "gatsby-plugin-asset-path"
        }
    ]
}

In our use case above, we have assetPrefix set as followed:

{
  assetPrefix: `/assets/${Date.now().toString()}`,
}

Options

removeMapFiles

Default: false

Stops Webpack from generating the .js.map files

// Your gatsby-config.js
{
  plugins: [
    {
      resolve: "gatsby-plugin-asset-path",
      options: {
        removeMapFiles: true,
      },
    },
  ];
}

paths

Default: ["static", "page-data"]

The paths of files/folders to be copied to the asset directory. Do not add icons since these are copied and duplicated across /public/icons/ and /public/${assetPrefix}/.

// Your gatsby-config.js
{
  plugins: [
    {
      resolve: "gatsby-plugin-asset-path",
      options: {
        paths: ["static"],
      },
    },
  ];
}

fileTypes

Default: ["js", "css"]

The types of files in the root publicFolder to be copied to the asset directory.

// Your gatsby-config.js
{
  plugins: [
    {
      resolve: "gatsby-plugin-asset-path",
      options: {
        fileTypes: ["js", "map", "css"],
      },
    },
  ];
}

DEPLOY

Update version in package.json then release via github releases with same tag #!