React+es6下的webpack.config.js怎么写
1个回答
2016-12-13 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
参考github上面的示例:
https://github.com/newtriks/generator-react-webpack
'use strict';
let opts = require('./configopts.json');
/**
* Get a setting
* @param {String} setting
* @return {Mixed} setting or null if not found
*/
let getSetting = (setting) => {
return opts[setting] !== undefined ? opts[setting] : null;
}
/**
* Get choices for a given setting
* @param {String} setting
* @return {Mixed} Result or null if nothing was found
*/
let getChoices = function getChoices(setting) {
let config = getSetting(setting);
return config && Array.isArray(config.options) ? config.options : null;
}
/**
* Get the wanted choice by key
* @param {String} setting
* @param {String} key
* @return {Object}
*/
let getChoiceByKey = (setting, key) => {
let choices = getChoices(setting);
if(!choices) {
return null;
}
let result = null;
for(let choice of choices) {
if(choice.name === key) {
result = choice;
break;
}
}
return result;
}
/**
* Get the default choice for a config setting
* @param {String} setting
* @return {Mixed}
*/
let getDefaultChoice = (setting) => {
let config = getSetting(setting);
return config && config.default !== undefined && config.default.length > 0 ? config.default : null;
}
// getChoices
// getDefault
module.exports = {
getSetting: getSetting,
getChoices: getChoices,
getChoiceByKey: getChoiceByKey,
getDefaultChoice: getDefaultChoice
};
https://github.com/newtriks/generator-react-webpack
'use strict';
let opts = require('./configopts.json');
/**
* Get a setting
* @param {String} setting
* @return {Mixed} setting or null if not found
*/
let getSetting = (setting) => {
return opts[setting] !== undefined ? opts[setting] : null;
}
/**
* Get choices for a given setting
* @param {String} setting
* @return {Mixed} Result or null if nothing was found
*/
let getChoices = function getChoices(setting) {
let config = getSetting(setting);
return config && Array.isArray(config.options) ? config.options : null;
}
/**
* Get the wanted choice by key
* @param {String} setting
* @param {String} key
* @return {Object}
*/
let getChoiceByKey = (setting, key) => {
let choices = getChoices(setting);
if(!choices) {
return null;
}
let result = null;
for(let choice of choices) {
if(choice.name === key) {
result = choice;
break;
}
}
return result;
}
/**
* Get the default choice for a config setting
* @param {String} setting
* @return {Mixed}
*/
let getDefaultChoice = (setting) => {
let config = getSetting(setting);
return config && config.default !== undefined && config.default.length > 0 ? config.default : null;
}
// getChoices
// getDefault
module.exports = {
getSetting: getSetting,
getChoices: getChoices,
getChoiceByKey: getChoiceByKey,
getDefaultChoice: getDefaultChoice
};
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询