react-cosmos
Version:
CLI for running React Cosmos inside webpack-powered apps
95 lines (69 loc) • 3.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createWebpackCosmosConfig = createWebpackCosmosConfig;
var _path = _interopRequireDefault(require("path"));
var _resolveModule = require("../../../config/resolveModule");
var _fs = require("../../../shared/fs");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createWebpackCosmosConfig(cosmosConfig) {
var rootDir = cosmosConfig.rootDir;
var configInput = cosmosConfig.webpack || {};
return {
configPath: getWebpackConfigPath(configInput, rootDir),
overridePath: getWebpackOverridePath(configInput, rootDir),
includeHashInOutputFilename: getIncludeHashInOutputFilename(configInput),
hotReload: getHotReload(configInput),
reloadOnFail: getReloadOnFail(configInput)
};
}
function getWebpackConfigPath(_ref, rootDir) {
var configPath = _ref.configPath;
if (typeof configPath === 'undefined') {
return (0, _resolveModule.resolveModule)(rootDir, 'webpack.config.js');
} // User can choose to prevent automatical use of an existing webpack.config.js
// file (relative to the root dir) by setting configPath to null
if (!configPath) {
return null;
}
var absPath = (0, _resolveModule.resolveModule)(rootDir, configPath);
if (!(0, _fs.fileExists)(absPath)) {
var relPath = _path.default.relative(process.cwd(), absPath);
throw new Error("webpack config not found at path: ".concat(relPath));
}
return absPath;
}
function getWebpackOverridePath(_ref2, rootDir) {
var overridePath = _ref2.overridePath;
if (typeof overridePath === 'undefined') {
return (0, _resolveModule.resolveModule)(rootDir, 'webpack.override.js');
} // User can choose to prevent automatical use of an existing webpack.override.js
// file (relative to the root dir) by setting overridePath to null
if (!overridePath) {
return null;
}
var absPath = (0, _resolveModule.resolveModule)(rootDir, overridePath);
if (!(0, _fs.fileExists)(absPath)) {
var relPath = _path.default.relative(process.cwd(), absPath);
throw new Error("webpack override module not found at path: ".concat(relPath));
}
return absPath;
} // Default value is False to not break backwards compatibility
// In future releases it's better to mark this as @deprecated and set
// output.filename to "[name].[contenthash].js" by default
function getIncludeHashInOutputFilename(_ref3) {
var _ref3$includeHashInOu = _ref3.includeHashInOutputFilename,
includeHashInOutputFilename = _ref3$includeHashInOu === void 0 ? false : _ref3$includeHashInOu;
return includeHashInOutputFilename;
}
function getHotReload(_ref4) {
var _ref4$hotReload = _ref4.hotReload,
hotReload = _ref4$hotReload === void 0 ? true : _ref4$hotReload;
return hotReload;
}
function getReloadOnFail(_ref5) {
var _ref5$reloadOnFail = _ref5.reloadOnFail,
reloadOnFail = _ref5$reloadOnFail === void 0 ? true : _ref5$reloadOnFail;
return reloadOnFail;
}