@wjunt/webpack-config
Version:
Presets of webpack config
48 lines (47 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const path = require("path");
/**
* Get cache-loader for caching.
* @param options
*/
function getCacheLoader(options) {
if (typeof options === 'undefined' || options === true) {
options = {};
}
return {
loader: 'cache-loader',
options: lodash_1.defaultsDeep(options, {
cacheDirectory: path.resolve('node_modules', '.cache'),
}),
};
}
exports.getCacheLoader = getCacheLoader;
function combineRule(rule, defaults) {
for (let key of Object.keys(rule)) {
if (key === 'options' || key === 'cacheable') {
continue;
}
if (key === 'usePrepend') {
defaults.use = toArray(rule[key]).concat(toArray(defaults.use));
continue;
}
if (key === 'useAppend') {
defaults.use = toArray(defaults.use).concat(toArray(rule[key]));
continue;
}
defaults[key] = rule[key];
}
return defaults;
}
exports.combineRule = combineRule;
function toArray(value) {
if (!value) {
return [];
}
if (Array.isArray(value)) {
return value;
}
return [value];
}