UNPKG

1.25 kBMarkdownView Raw
1Webpack Env
2================
3[![Build Status](https://travis-ci.org/toastynerd/webpack_env.svg)](https://travis-ci.org/toastynerd/webpack_env)
4
5Webpack ENV is a webpack plug-in for creating ENV-variable-like globals in webpack.
6
7## Setup
8First add Webpack Env as a webpack plug-in, using gulp this would
9look something like this:
10```js
11//gulpfile.js
12var gulp = require('gulp');
13var webpack = require('webpack');
14var webpackEnv = require('webpack-env');
15
16gulp.task('webpack', function() {
17 return gulp.src('./entry.js')
18 .pipe(webpack({
19 output: {
20 filename: 'bundle.js'
21 },
22 plugins: [webpackEnv]
23 }))
24 .pipe(gulp.dest('build/'));
25});
26```
27Create a `.env.js` file in the same directory as your gulpfile.js.
28This file should export an object that contains the eventual globals
29you want your webpack code to contain:
30```js
31module.exports = {
32 SOME_VAR: 'some val'
33}
34```
35
36## Multiple Environments
37
38Weback Env also supports having multiple files for multiple environments.
39To create a set of Production environment globals, just create a `.production_env.js`
40file and run gulp with NODE_ENV set to 'production'.
41
42## Keep your secrets out of the repo
43
44Be sure you've added all your `.env` files to your `.gitignore`.