Gathering detailed insights and metrics for next-env-replace
Gathering detailed insights and metrics for next-env-replace
Gathering detailed insights and metrics for next-env-replace
Gathering detailed insights and metrics for next-env-replace
npm install next-env-replace
Typescript
Module System
Node Version
NPM Version
69.2
Supply Chain
98.2
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Oct 08, 2024
Latest Version
1.0.0
Package Id
next-env-replace@1.0.0
Unpacked Size
10.77 kB
Size
4.23 kB
File Count
4
NPM Version
10.5.0
Node Version
20.12.1
Published on
Oct 08, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
next-env-replace
bridges the gap in Next.js by enabling the "Build once, deploy many" philosophy. It allows you to build your application once and deploy it across multiple environments without the need for rebuilding, adhering to the twelve-factor methodology and facilitating continuous delivery.
In Next.js, environment variables are typically baked into the build, requiring separate builds for different environments. This contradicts the "Build once, deploy many" principle, which is essential for easy deployment and testability. next-env-replace
solves this problem by allowing you to replace environment variables at runtime, ensuring that the same build can be deployed across various environments without modifications.
NEXT_PUBLIC_*
environment variables at runtime.Install the package using npm:
1npm install next-env-replace
or with yarn:
1yarn add next-env-replace
Build your Next.js application using next-env-replace
to set placeholder environment variables:
1npx next-env-replace set-env-vars -- next build
This command locates all NEXT_PUBLIC_*
variables and sets them with placeholder values during the build process.
Before starting your application, replace the placeholder values with the actual environment variables available at runtime:
1npx next-env-replace replace-env-vars && next start
Here is how your Dockerfile could look:
1FROM node:22-alpine 2WORKDIR /app 3COPY package*.json ./ 4RUN npm install 5COPY . . 6RUN npm run build # Notice the build happens once 7EXPOSE 3000 8 9CMD ["npm", "start"] # The start command runs each time the container starts
Update your package.json
scripts as follows:
1{ 2 "scripts": { 3 "dev": "next dev", 4 "build": "next-env-replace set-env-vars -- next build", 5 "start": "next-env-replace replace-env-vars && next start" 6 } 7}
That's it! No code changes are required, and assuming the actual environment variables are provided at runtime, the placeholder values will be replaced by the real values.
Build Time: During the build process, next-env-replace
scans your codebase for all NEXT_PUBLIC_*
environment variables and replaces them with placeholder values. This allows the application to be built without needing the actual environment-specific values.
Runtime: When the application starts, next-env-replace
replaces the placeholder values with the actual environment variables available at runtime. This process is significantly faster than rebuilding the application and ensures that the correct values are used in each environment.
One of the main advantages of next-env-replace
is that it requires no changes to your code. You can continue using environment variables in your code as usual. The module handles the replacement process transparently.
MIT License
No vulnerabilities found.
No security vulnerabilities found.