diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8364a02 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Breno Jesus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..059dcbe --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +# 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: + +```bash +npm install next-plugin-cdn +``` + +or + +```bash +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: + +```javascript + +// 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 \ No newline at end of file diff --git a/package.json b/package.json index cf0f00a..2f24906 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-plugin-cdn", - "version": "0.0.10", + "version": "0.1.0", "description": "", "types": "lib/esm/index.d.ts", "main": "lib/cjs/index.js",