mirror of
https://github.com/wassname/react-webpack-template.git
synced 2026-06-27 18:25:20 +08:00
Refactoring: Removed lodash as dependency, refactored webpack config (including minor speed improvements)
This commit is contained in:
+9
-18
@@ -1,10 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var args = require('minimist')(process.argv.slice(2));
|
||||
const path = require('path');
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
|
||||
// List of allowed environments
|
||||
var allowedEnvs = ['dev', 'dist', 'test'];
|
||||
const allowedEnvs = ['dev', 'dist', 'test'];
|
||||
|
||||
// Set the correct environment
|
||||
var env;
|
||||
@@ -18,31 +18,22 @@ if(args._.length > 0 && args._.indexOf('start') !== -1) {
|
||||
process.env.REACT_WEBPACK_ENV = env;
|
||||
|
||||
// Get available configurations
|
||||
var configs = {
|
||||
const configs = {
|
||||
base: require(path.join(__dirname, 'cfg/base')),
|
||||
dev: require(path.join(__dirname, 'cfg/dev')),
|
||||
dist: require(path.join(__dirname, 'cfg/dist')),
|
||||
test: require(path.join(__dirname, 'cfg/test'))
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an allowed environment
|
||||
* @param {String} env
|
||||
* @return {String}
|
||||
*/
|
||||
function getValidEnv(env) {
|
||||
var isValid = env && env.length > 0 && allowedEnvs.indexOf(env) !== -1;
|
||||
return isValid ? env : 'dev';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the webpack configuration
|
||||
* @param {String} env Environment to use
|
||||
* @param {String} wantedEnv The wanted environment
|
||||
* @return {Object} Webpack config
|
||||
*/
|
||||
function buildConfig(env) {
|
||||
var usedEnv = getValidEnv(env);
|
||||
return configs[usedEnv];
|
||||
function buildConfig(wantedEnv) {
|
||||
let isValid = wantedEnv && wantedEnv.length > 0 && allowedEnvs.indexOf(wantedEnv) !== -1;
|
||||
let validEnv = isValid ? wantedEnv : 'dev';
|
||||
return configs[validEnv];
|
||||
}
|
||||
|
||||
module.exports = buildConfig(env);
|
||||
|
||||
Reference in New Issue
Block a user