All Projects β†’ madecomfy β†’ gatsby-plugin-asset-path

madecomfy / gatsby-plugin-asset-path

Licence: MIT license
Move all of your JS and CSS build files, as well as the static folder into a subdirectory of your choice

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gatsby-plugin-asset-path

gatsby-theme-gallery
🏞 A Gatsby Theme for adding a gallery to your site.
Stars: ✭ 40 (+185.71%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-theme-nehalem
A Gatsby blog theme.
Stars: ✭ 168 (+1100%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (+0%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-optimize-svgs
A Gatsby Plugin to minify SVGs output to the filesystem during the build.
Stars: ✭ 39 (+178.57%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-open-graph-images
πŸ–Ό Open-Graph Images derived and generated from React Components
Stars: ✭ 16 (+14.29%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-disqus
πŸ’¬ A plugin for adding Disqus comments to GatsbyJS
Stars: ✭ 40 (+185.71%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-robots-txt
Gatsby plugin that automatically creates robots.txt for your site
Stars: ✭ 105 (+650%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-lunr
Gatsby plugin for full text search implementation based on lunr client-side index. Supports multilanguage search.
Stars: ✭ 69 (+392.86%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-theme-jam-example
An example submission for the Gatsby Theme Jam.
Stars: ✭ 89 (+535.71%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-remark-classes
Automatically add class attributes to markdown elements
Stars: ✭ 12 (-14.29%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-firestore
Gatsby source plugin for building websites using the Firestore as a data source.
Stars: ✭ 30 (+114.29%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-remark-images-anywhere
Handle images with relative, absolute & remote path for gatsby-transformer-remark & gatsby-plugin-mdx
Stars: ✭ 22 (+57.14%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-apollo-client
πŸ“‘Inject a Shopify Apollo Client into the browser.
Stars: ✭ 20 (+42.86%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-moltin
πŸš€ Gatsby source plugin for building Elastic Path Commerce Cloud powered eCommerce websites
Stars: ✭ 21 (+50%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-plugin-prettier-build
prettify gatsby build output
Stars: ✭ 30 (+114.29%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-theme-deck-n-blog
Create a deck (with mdx-deck) and a blog post from the same MDX
Stars: ✭ 17 (+21.43%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-source-stripe
Gatsby source plugin for building websites using Stripe as a data source
Stars: ✭ 71 (+407.14%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-i18n
Gatsby plugin that provides i18n support
Stars: ✭ 25 (+78.57%)
Mutual labels:  gatsby, gatsby-plugin
chandrikadeb7.github.io
Personal portfolio website hosted using GitHub Pages - Version 2
Stars: ✭ 99 (+607.14%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-theme-dox
Documentation made easy with Gatsby. πŸŽ‰
Stars: ✭ 29 (+107.14%)
Mutual labels:  gatsby, gatsby-plugin

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 #!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].