@@ -75,74 +75,57 @@ When we do have multiple configurations in mind for different environments, the
75
75
each environment. For example:
76
76
##config/dev.js
77
77
``` js
78
- module .exports = function (env ) {
78
+ module .exports = function (env ) {
79
79
debug: true ,
80
80
devtool: ' cheap-module-source-map' ,
81
81
output: {
82
- path: path .join (__dirname , ' /../dist/assets' ),
83
- filename: ' [name].bundle.js' ,
84
- publicPath: publicPath,
85
- sourceMapFilename: ' [name].map'
82
+ path: path .join (__dirname , ' /../dist/assets' ),
83
+ filename: ' [name].bundle.js' ,
84
+ publicPath: publicPath,
85
+ sourceMapFilename: ' [name].map'
86
86
},
87
87
devServer: {
88
- port: 7777 ,
89
- host: ' localhost' ,
90
- historyApiFallback: true ,
91
- noInfo: false ,
92
- stats: ' minimal' ,
93
- publicPath: publicPath
94
- },
95
- });
88
+ port: 7777 ,
89
+ host: ' localhost' ,
90
+ historyApiFallback: true ,
91
+ noInfo: false ,
92
+ stats: ' minimal' ,
93
+ publicPath: publicPath
94
+ }
95
+ }
96
96
```
97
97
##config/prod.js
98
98
``` js
99
- module .exports = function (env ) {
100
- debug: false ,
99
+ module .exports = function (env ) {
100
+ debug: false ,
101
101
output: {
102
- path: path .join (__dirname , ' /../dist/assets' ),
103
- filename: ' [name].bundle.js' ,
104
- publicPath: publicPath,
105
- sourceMapFilename: ' [name].map'
102
+ path: path .join (__dirname , ' /../dist/assets' ),
103
+ filename: ' [name].bundle.js' ,
104
+ publicPath: publicPath,
105
+ sourceMapFilename: ' [name].map'
106
106
},
107
107
plugins: [
108
- new webpack.LoaderOptionsPlugin ({
109
- minimize: true ,
110
- debug: false
111
- }),
112
- new UglifyJsPlugin ({
113
- beautify: false ,
114
- mangle: { screw_ie8 : true , keep_fnames: true },
115
- compress: { screw_ie8: true },
116
- comments: false
117
- })
108
+ new webpack.LoaderOptionsPlugin ({
109
+ minimize: true ,
110
+ debug: false
111
+ }),
112
+ new UglifyJsPlugin ({
113
+ beautify: false ,
114
+ mangle: {
115
+ screw_ie8: true ,
116
+ keep_fnames: true
117
+ },
118
+ compress: {
119
+ screw_ie8: true
120
+ },
121
+ comments: false
122
+ })
118
123
]
119
- });
124
+ }
120
125
```
121
126
Have our webpack.config.js has the following snippet:
122
127
``` js
123
- function buildConfig (env ) {
124
- var config;
125
- switch (env) {
126
- case ' prod' :
127
- config = require (' ./config/prod.js' )({env: ' prod' });
128
- break ;
129
- case ' qa' :
130
- config = require (' ./config/qa.js' )({env: ' qa' });
131
- break ;
132
- case ' test' :
133
- config = require (' ./config/test.js' )({env: ' test' });
134
- break ;
135
- case ' dev' :
136
- config = require (' ./config/dev.js' )({env: ' dev' });
137
- break ;
138
- default :
139
- config = require (' ./config/dev.js' )({env: ' dev' });
140
- break ;
141
- }
142
- return config;
143
- }
144
-
145
- module .exports = buildConfig (env);
128
+ return require (' ./config/' + env + ' .js' )({ env: env })
146
129
```
147
130
And from our package.json, where we build our application using webpack, the command goes like this:
148
131
``` js
0 commit comments