ci
lihbr utils for Netlify
@lihbr/utils-netlify.ci
provides utils for Netlify Build process.
Features
Check if build process is ran within Netlify
Check if it's a deployment for production or something else (preview, staging, etc.)
Get the final deploy URL, even for branch subdomains
Installation
Add @lihbr/utils-netlify.ci
dependency to your project:
yarn add @lihbr/utils-netlify.ci
npm install @lihbr/utils-netlify.ci
That's it!
Usage
Just import the module inside your build script:
const ci = require("@lihbr/utils-netlify.ci");
Reference
Methods
isNetlify()
Returns true if on Netlify by checking the NETLIFY environment-variables.
if (ci.isNetlify()) {
// Perform Netlify only actions...
}
isProduction()
Returns true if on a production build by checking the CONTEXT environment-variables.
if (ci.isProduction()) {
// Perform production only actions...
}
getFinalDeployUrl({ branchDomains })
branchDomains
- An array of branches having a branch domain
- Type:
Array
- Default:
[]
Returns the final deploy URL, taking branch subdomains into account.
const APP_URL = ci.getFinalDeployUrl({ branchDomains: ["staging"] });
/**
* For master branch deploy:
* https://example.com
*
* For staging branch deploy:
* https://staging.example.com
*
* For feature-branch deploy:
* https://feature-branch--example.netlify.app
*
* For a deploy preview:
* https://5b243e66dd6a547b4fee73ae--example.netlify.app
*/
Example
You can check out a full example usage of these utils across this Nuxt.js configuration file: nuxt.config.js, search for ci.
Edit this page on GitHub
Updated at Thu, Apr 21, 2022