co2-emissions-audit v1.0.1
CO2 Emission Audit
🌍 Purpose & Motivation
Modern web applications can be energy-intensive, leading to higher carbon footprints. The CO2 Emission Audit aims to quantify and reduce web-related carbon emissions by analyzing Webpack output files and their environmental impact.
By using this plugin, developers can:
- Measure the carbon emissions of each file in a Webpack build.
- Set thresholds to prevent excessive energy consumption.
- Grade file emissions using the Digital Carbon Rating Scale.
- Fail the build if emissions exceed a specified level.
- Generate reports in JSON and CSV formats for sustainability tracking.
🚀 Features
- ✅ CO₂ Emission Calculation per file & total build
- ✅ Threshold Checking to flag oversized assets
- ✅ Digital Carbon Rating Scale for grading sustainability
- ✅ Build Failure Option for excessive CO₂ emissions
- ✅ CSV & JSON Reports for tracking and optimization
- ✅ Customizable thresholds and failure levels
📦 Installation
npm install --save-dev co2-emission-audit
or
yarn add -D co2-emission-audit
⚙️ Usage
Add the plugin to your Webpack configuration:
const CO2EmissionAudit = require('co2-emission-audit');
module.exports = {
// Other webpack configurations...
plugins: [
new CO2EmissionAudit({
thresholds: {
'.js': 0.005, // Max CO₂ per byte for JavaScript files
'.css': 0.002,
'.png': 0.005
},
failThreshold: 'D', // Fail build if total grade is D or worse
})
]
};
📊 Report Output
After a Webpack build, the plugin generates:
: A structured JSON report
: A CSV file for tracking sustainability
Example console output:
CO₂ Emission Report:
┌───────────────┬──────────────┬───────────┬───────────────────────────┐
│ File │ Size (bytes) │ CO₂ (g) │ Grade │
├───────────────┼──────────────┼───────────┼───────────────────────────┤
│ main.js │ 152340 │ 0.001523 │ B 🟢 (Good) │
│ image.png │ 905230 │ 0.009052 │ E 🔴 (Very High) │
└───────────────┴──────────────┴───────────┴───────────────────────────┘
Total Build Size: 1095804 bytes
Total CO₂ Emissions: 0.010977 g
Overall Build Grade: C 🟡 (Moderate)
If emissions exceed thresholds, the build can fail:
ERROR in CO2EmissionAudit
Build failed due to high CO₂ emissions. Grade: D 🟠 (High)
🤝 Contributing
We welcome contributions! To contribute:
- Fork the repository
- Create a new branch (
feature/new-feature
) - Commit your changes
- Open a pull request
Development Setup
Clone the repo and install dependencies:
git clone https://github.com/your-repo/co2-emission-audit.git
cd co2-emission-audit
npm install
Run tests:
npm test
🛠️ Maintainers
This project is maintained by Paul McGann and the Open Source Community. If you have any questions, feel free to open an issue or submit a PR.
📄 License
This project is licensed under the MIT License. See LICENSE for details.
🚀 Let's build a more sustainable web, one optimized asset at a time!