Coder Social home page Coder Social logo

brenordr / next-plugin-cdn Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 0.0 69 KB

Next.js plugin for automatic asset uploading to a CDN during build time. Improve website performance and reduce load times.

Home Page: https://www.npmjs.com/package/next-plugin-cdn

License: MIT License

TypeScript 100.00%
asset-uploader aws-s3 build-time cdn cloudflare content-delivery content-delivery-network google-cloud-storage load-time nextjs

next-plugin-cdn's Introduction

Next.js Plugin CDN ๐ŸŒ

This library is a plugin for Next.js that automatically uploads your static assets to a specified CDN during build time and configures your Next.js application to use the specified CDN prefix. This makes it easy to set up and optimize your assets for better performance.

Currently, it supports Google Cloud Storage, but support is planned to other CDNs such as AWS S3, Cloudflare, and more in the future! ๐ŸŒŸ

๐Ÿ“ฆ Installation

Install the package using your favorite package manager:

npm install next-plugin-cdn

or

yarn add next-plugin-cdn

๐Ÿ”ง Usage

Set the appropriate environment variables for your project.

In your next.config.js, import the plugin and use it to configure your application:

// Import the plugin and pass cdn info and credentials
// for example using env vars:
const withCDN = require("next-plugin-cdn").default({
  domain: process.env.NODE_ENV === "production" && process.env.CDN_DOMAIN,
  provider: process.env.CDN_PROVIDER,
  bucket: process.env.CDN_BUCKET,
  keyFilename: process.env.CDN_KEY_FILENAME,
});


// Then just apply to your nextjs config
/** @type {import('next').NextConfig} */
const nextConfig = withCDN({
  output: "standalone",
  reactStrictMode: true,
  swcMinify: true,
  experimental: {
    appDir: true,
  },
});

module.exports = nextConfig;

Now, during the build process, the plugin will upload your static assets to the specified CDN and configure your Next.js application to use the CDN prefix. ๐ŸŽ‰

โš™๏ธ Options

The withCDN function accepts an object with the following properties:

  • domain: The domain of your CDN. This should be set to the value of the CDN_DOMAIN environment variable.
  • provider: The CDN provider you are using (e.g., google, aws, cloudflare, etc.). This should be set to the value of the CDN_PROVIDER environment variable.
  • bucket: The name of the bucket where your assets will be uploaded. This should be set to the value of the CDN_BUCKET environment variable.
  • keyFilename: The name of the JSON key file used for authentication with the CDN provider. This should be set to the value of the CDN_KEY_FILENAME environment variable.

These options are passed to the plugin, which then takes care of uploading the assets and configuring the CDN prefix. ๐Ÿ› ๏ธ

๐Ÿ›ฃ๏ธ Roadmap

  • Google Cloud Storage support
  • AWS S3 support
  • Cloudflare support
  • Other CDNs support (let me know if others are interesting)

Stay tuned for more CDN provider support! ๐Ÿšง

๐Ÿ“„ License

MIT License

next-plugin-cdn's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.