Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(environment): add plugin #2

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Environment Plugin

Pass environment variables to app with [`dotenv`](https://github.com/motdotla/dotenv) and custom variables

## Install

```
npm install -D @rambler-tech/razzle-environment
```

or

```
yarn add -D @rambler-tech/razzle-environment
```

## Usage

Add the plugin to `razzle.config.js`

```js
const EnvironmentPlugin = require('@rambler-tech/razzle-environment')

const VERSION = '...'

module.exports = {
plugins: [
EnvironmentPlugin({
VERSION
})
],
modifyWebpackConfig({webpackConfig}) {
// ...
return webpackConfig
}
}
```
18 changes: 18 additions & 0 deletions packages/environment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require('dotenv').config()

const webpack = require('webpack')
const DotenvPlugin = require('dotenv-webpack')

module.exports = (variables) => ({
modifyWebpackConfig({webpackConfig}) {
webpackConfig.plugins = [
...webpackConfig.plugins,
new webpack.EnvironmentPlugin(variables),
new DotenvPlugin({
systemvars: true
})
]

return webpackConfig
}
})
18 changes: 18 additions & 0 deletions packages/environment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@rambler-tech/razzle-environment",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"dependencies": {
"dotenv": "^16.3.1",
"dotenv-webpack": "^8.0.1"
},
"peerDependencies": {
"razzle": ">=4",
"webpack": ">=5"
}
}
21 changes: 20 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2124,16 +2124,35 @@ dot-prop@^5.1.0:
dependencies:
is-obj "^2.0.0"

dotenv-defaults@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz#6b3ec2e4319aafb70940abda72d3856770ee77ac"
integrity sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==
dependencies:
dotenv "^8.2.0"

dotenv-expand@~10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@~16.3.1:
dotenv-webpack@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-8.0.1.tgz#6656550460a8076fab20e5ac2eac867e72478645"
integrity sha512-CdrgfhZOnx4uB18SgaoP9XHRN2v48BbjuXQsZY5ixs5A8579NxQkmMxRtI7aTwSiSQcM2ao12Fdu+L3ZS3bG4w==
dependencies:
dotenv-defaults "^2.0.2"

dotenv@^16.3.1, dotenv@~16.3.1:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==

dotenv@^8.2.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"
integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==

duplexer@^0.1.1, duplexer@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"
Expand Down
Loading