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