Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvdvleuten committed Aug 24, 2017
0 parents commit fcfc368
Show file tree
Hide file tree
Showing 7 changed files with 3,349 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js

sudo: false

node_js:
- 6
- 4

cache: yarn
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Robin van der Vleuten <robin@webstronauts.co>

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.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# preact-cli-plugin-env-vars

Consume variables in your environment with the Preact CLI.

[![NPM version](https://img.shields.io/npm/v/preact-cli-plugin-env-vars.svg)](https://www.npmjs.com/package/preact-cli-plugin-env-vars)
[![Build Status](https://travis-ci.org/robinvdvleuten/preact-cli-plugin-env-vars.svg?branch=master)](https://travis-ci.org/robinvdvleuten/preact-cli-plugin-env-vars)

## Installation

```
$ yarn add preact-cli-plugin-env-vars --dev
```

Alternatively using npm:

```
$ npm i preact-cli-plugin-env-vars --save-dev
```

And include in your project by creating a `preact.config.js`:

```js
const envVars = require('preact-cli-plugin-env-vars');

export default function (config) {
envVars(config);
}
```

## Usage

The plugin allows to use any environment variables prefixed with `PREACT_APP_` to be used within your script:

```js
console.log(process.env.PREACT\_APP\_SECRET_CODE);
```

The environment variables are embedded during the build time.

## License

MIT © [Robin van der Vleuten](https://www.robinvdvleuten.nl)
26 changes: 26 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const webpack = require('webpack');

const PREACT_APP = /^PREACT_APP_/i;

const getEnvVars = () => {
const raw = Object.keys(process.env)
.filter(key => PREACT_APP.test(key))
.reduce(
(env, key) => Object.assign(env, { [key]: process.env[key] }),
{}
);

const stringified = {
'process.env': Object.keys(raw).reduce(
(env, key) => Object.assign(env, { [key]: JSON.stringify(raw[key]) }),
{}
)
};

return { raw, stringified };
};

module.exports = config => {
const env = getEnvVars();
config.plugins.push(new webpack.DefinePlugin(env.stringified));
};
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "preact-cli-plugin-env-vars",
"version": "1.0.0",
"description": "Consume variables in your environment with the Preact CLI",
"license": "MIT",
"author": "Robin van der Vleuten <robin@webstronauts.co>",
"main": "lib/index.js",
"keywords": [
"preact",
"plugin",
"env"
],
"files": [
"lib"
],
"scripts": {
"test": "xo"
},
"xo": {
"esnext": true,
"space": true,
"semicolon": true,
"rules": {
"object-curly-spacing": [
"error",
"always"
]
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/robinvdvleuten/preact-cli-plugin-env-vars.git"
},
"bugs": {
"url": "https://github.com/robinvdvleuten/preact-cli-plugin-env-vars/issues"
},
"homepage": "https://github.com/robinvdvleuten/preact-cli-plugin-env-vars#readme",
"devDependencies": {
"webpack": "^2.3.3",
"xo": "^0.18.2"
}
}
Loading

0 comments on commit fcfc368

Please sign in to comment.