@modern-js/module-tools-v2
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
148 lines (146 loc) • 10.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validPartialBuildConfig = exports.validBuildTypeAndFormat = exports.mergeDefaultBaseConfig = exports.mergeBundlelessBaseConfig = exports.mergeBundleBaseConfig = exports.getDtsConfig = void 0;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const validPartialBuildConfig = config => {
if (Array.isArray(config)) {
for (const c of config) {
validBuildTypeAndFormat(c);
}
} else {
validBuildTypeAndFormat(config);
}
};
exports.validPartialBuildConfig = validPartialBuildConfig;
const validBuildTypeAndFormat = config => {
var _config$format;
if (config.buildType === 'bundleless' && ['iife', 'umd'].includes((_config$format = config.format) !== null && _config$format !== void 0 ? _config$format : '')) {
throw new Error(`when buildType is bundleless, the format must be equal to one of the allowed values: (cjs, esm)`);
}
};
exports.validBuildTypeAndFormat = validBuildTypeAndFormat;
const mergeDefaultBaseConfig = async (pConfig, context) => {
if (pConfig.buildType === 'bundle') {
return mergeBundleBaseConfig(pConfig, context);
}
return mergeBundlelessBaseConfig(pConfig);
};
exports.mergeDefaultBaseConfig = mergeDefaultBaseConfig;
const mergeBundleBaseConfig = async (pConfig, context) => {
var _boptions$entry, _boptions$platform, _boptions$splitting, _boptions$minify, _boptions$skipDeps, _boptions$entryNames, _boptions$globals, _boptions$metafile, _boptions$umdModuleNa, _boptions$externals, _pConfig$format, _pConfig$target, _pConfig$sourceMap, _pConfig$copy, _pConfig$path, _pConfig$jsx;
const {
defaultBundleBuildConfig: defaultConfig
} = await Promise.resolve().then(() => _interopRequireWildcard(require("../constants/build")));
const {
cloneDeep
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils/lodash')));
const {
getDefaultIndexEntry
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./entry")));
const finalEntry = await getDefaultIndexEntry(context);
const {
bundleOptions: boptions
} = pConfig;
const bundleOptions = boptions ? {
entry: (_boptions$entry = boptions.entry) !== null && _boptions$entry !== void 0 ? _boptions$entry : cloneDeep(finalEntry),
platform: (_boptions$platform = boptions.platform) !== null && _boptions$platform !== void 0 ? _boptions$platform : defaultConfig.bundleOptions.platform,
splitting: (_boptions$splitting = boptions.splitting) !== null && _boptions$splitting !== void 0 ? _boptions$splitting : defaultConfig.bundleOptions.splitting,
minify: (_boptions$minify = boptions.minify) !== null && _boptions$minify !== void 0 ? _boptions$minify : defaultConfig.bundleOptions.minify,
skipDeps: (_boptions$skipDeps = boptions.skipDeps) !== null && _boptions$skipDeps !== void 0 ? _boptions$skipDeps : defaultConfig.bundleOptions.skipDeps,
entryNames: (_boptions$entryNames = boptions.entryNames) !== null && _boptions$entryNames !== void 0 ? _boptions$entryNames : defaultConfig.bundleOptions.entryNames,
globals: (_boptions$globals = boptions.globals) !== null && _boptions$globals !== void 0 ? _boptions$globals : cloneDeep(defaultConfig.bundleOptions.globals),
metafile: (_boptions$metafile = boptions.metafile) !== null && _boptions$metafile !== void 0 ? _boptions$metafile : defaultConfig.bundleOptions.metafile,
umdModuleName: (_boptions$umdModuleNa = boptions.umdModuleName) !== null && _boptions$umdModuleNa !== void 0 ? _boptions$umdModuleNa : defaultConfig.bundleOptions.umdModuleName,
externals: (_boptions$externals = boptions.externals) !== null && _boptions$externals !== void 0 ? _boptions$externals : defaultConfig.bundleOptions.externals
} : _objectSpread(_objectSpread({}, cloneDeep(defaultConfig.bundleOptions)), {}, {
entry: cloneDeep(finalEntry)
});
return {
asset: _objectSpread({
path: './',
rebase: undefined,
name: undefined,
limit: undefined,
publicPath: undefined
}, pConfig.asset),
buildType: defaultConfig.buildType,
format: (_pConfig$format = pConfig.format) !== null && _pConfig$format !== void 0 ? _pConfig$format : defaultConfig.format,
target: (_pConfig$target = pConfig.target) !== null && _pConfig$target !== void 0 ? _pConfig$target : defaultConfig.target,
sourceMap: (_pConfig$sourceMap = pConfig.sourceMap) !== null && _pConfig$sourceMap !== void 0 ? _pConfig$sourceMap : defaultConfig.sourceMap,
copy: (_pConfig$copy = pConfig.copy) !== null && _pConfig$copy !== void 0 ? _pConfig$copy : cloneDeep(defaultConfig.copy),
path: (_pConfig$path = pConfig.path) !== null && _pConfig$path !== void 0 ? _pConfig$path : defaultConfig.path,
dts: await getDtsConfig(pConfig.dts, defaultConfig.dts),
jsx: (_pConfig$jsx = pConfig.jsx) !== null && _pConfig$jsx !== void 0 ? _pConfig$jsx : defaultConfig.jsx,
bundleOptions
};
};
exports.mergeBundleBaseConfig = mergeBundleBaseConfig;
const mergeBundlelessBaseConfig = async pConfig => {
var _pConfig$format2, _pConfig$target2, _pConfig$sourceMap2, _pConfig$copy2, _pConfig$path2, _pConfig$jsx2, _bundlelessOptions$so, _bundlelessOptions$st;
const {
defaultBundlelessBuildConfig: defaultConfig
} = await Promise.resolve().then(() => _interopRequireWildcard(require("../constants/build")));
const {
cloneDeep
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils/lodash')));
const {
bundlelessOptions
} = pConfig;
return {
asset: _objectSpread({
path: './',
rebase: undefined,
name: undefined,
limit: undefined,
publicPath: undefined
}, pConfig.asset),
buildType: defaultConfig.buildType,
format: (_pConfig$format2 = pConfig.format) !== null && _pConfig$format2 !== void 0 ? _pConfig$format2 : defaultConfig.format,
target: (_pConfig$target2 = pConfig.target) !== null && _pConfig$target2 !== void 0 ? _pConfig$target2 : defaultConfig.target,
sourceMap: (_pConfig$sourceMap2 = pConfig.sourceMap) !== null && _pConfig$sourceMap2 !== void 0 ? _pConfig$sourceMap2 : defaultConfig.sourceMap,
copy: (_pConfig$copy2 = pConfig.copy) !== null && _pConfig$copy2 !== void 0 ? _pConfig$copy2 : cloneDeep(defaultConfig.copy),
path: (_pConfig$path2 = pConfig.path) !== null && _pConfig$path2 !== void 0 ? _pConfig$path2 : defaultConfig.path,
dts: await getDtsConfig(pConfig.dts, defaultConfig.dts),
jsx: (_pConfig$jsx2 = pConfig.jsx) !== null && _pConfig$jsx2 !== void 0 ? _pConfig$jsx2 : defaultConfig.jsx,
bundlelessOptions: bundlelessOptions ? {
sourceDir: (_bundlelessOptions$so = bundlelessOptions.sourceDir) !== null && _bundlelessOptions$so !== void 0 ? _bundlelessOptions$so : defaultConfig.bundlelessOptions.sourceDir,
styleCompileMode: (_bundlelessOptions$st = bundlelessOptions.styleCompileMode) !== null && _bundlelessOptions$st !== void 0 ? _bundlelessOptions$st : defaultConfig.bundlelessOptions.styleCompileMode
} : cloneDeep(defaultConfig.bundlelessOptions)
};
};
exports.mergeBundlelessBaseConfig = mergeBundlelessBaseConfig;
const getDtsConfig = async (userDTS, defaultDTS) => {
const {
cloneDeep,
isUndefined,
isObject
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils/lodash')));
if (isUndefined(userDTS)) {
return cloneDeep(defaultDTS);
}
if (isObject(userDTS)) {
return _objectSpread(_objectSpread({}, defaultDTS), userDTS);
}
return userDTS;
// let finalRet;
// if (isUndefined(userDTS)) {
// finalRet = cloneDeep(defaultDTS);
// } else if (isObject(userDTS)) {
// finalRet = {
// ...defaultDTS,
// ...userDTS,
// };
// } else {
// finalRet = userDTS;
// }
// console.info('finalRet', finalRet);
// return finalRet;
};
exports.getDtsConfig = getDtsConfig;
//# sourceMappingURL=config.js.map