@modern-js/module-tools-v2
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
254 lines (253 loc) • 6.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.targets = exports.source = exports.schema = exports.presets = exports.bundlelessBuildConfigProperties = exports.bundleBuildConfigProperties = exports.buildPreset = exports.buildConfig = 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; }
const source = {
target: 'source',
schema: {
type: 'object',
additionalProperties: false,
properties: {
alias: {
typeof: ['object', 'function']
},
envVars: {
type: 'array'
},
globalVars: {
type: 'object'
}
}
}
};
exports.source = source;
const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020',
// The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.
'esnext'];
exports.targets = targets;
const presets = ['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd', ...['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd'].reduce((ret, crt) => {
return [...ret, ...targets.map(t => `${crt}-${t}`)];
}, [])];
exports.presets = presets;
const commonBuildConfigProperties = {
// entry: {
// type: ['string', 'array', 'object'],
// },
target: {
enum: targets
},
sourceMap: {
enum: [true, false, 'inline', 'external']
},
asset: {
type: 'object'
},
jsx: {
enum: ['automatic', 'transform']
},
bundleOptions: {
type: 'object',
properties: {
entry: {
type: ['array', 'object']
},
splitting: {
type: 'boolean'
},
externals: {
type: 'array',
items: {
anyOf: [{
instanceof: 'RegExp'
}, {
typeof: 'string'
}]
}
},
platform: {
enum: ['node', 'browser']
},
minify: {
enum: ['esbuild', 'terser', false]
},
skipDeps: {
if: {
type: 'object'
},
then: {
properties: {
dependencies: {
type: 'boolean'
},
peerDependencies: {
type: 'boolean'
}
}
},
else: {
type: 'boolean'
}
},
terserOptions: {
type: 'object'
}
}
},
bundlelessOptions: {
type: 'object',
properties: {
style: {
type: 'object',
properties: {
compileMode: {
enum: ['all', 'only-compiled-code', 'only-source-code', false]
},
path: {
type: 'string'
}
}
},
assets: {
type: 'object',
properties: {
path: {
type: 'string'
}
}
}
}
},
dts: {
if: {
type: 'object'
},
then: {
properties: {
distPath: {
type: 'string'
},
tsconfigPath: {
type: 'string'
}
}
},
else: {
type: 'boolean'
}
},
path: {
type: 'string'
},
copy: {
type: 'object',
properties: {
patterns: {
type: 'array',
items: {
type: 'object',
properties: {
from: {
type: 'string'
},
to: {
type: 'string'
},
context: {
type: 'string'
},
globOptions: {
type: 'object'
}
}
}
},
options: {
type: 'object',
properties: {
concurrency: {
type: 'number'
}
}
}
}
}
};
const bundleBuildConfigProperties = {
buildType: {
enum: ['bundle']
},
format: {
enum: ['cjs', 'esm', 'umd', 'iife']
}
};
exports.bundleBuildConfigProperties = bundleBuildConfigProperties;
const bundlelessBuildConfigProperties = {
buildType: {
enum: ['bundleless']
},
format: {
enum: ['cjs', 'esm']
}
};
exports.bundlelessBuildConfigProperties = bundlelessBuildConfigProperties;
const buildConfig = {
target: 'buildConfig',
schema: {
if: {
type: 'array'
},
then: {
items: [{
type: 'object',
if: {
properties: bundleBuildConfigProperties
},
then: {
properties: _objectSpread(_objectSpread({}, bundleBuildConfigProperties), commonBuildConfigProperties),
additionalProperties: false
},
else: {
properties: _objectSpread(_objectSpread({}, bundlelessBuildConfigProperties), commonBuildConfigProperties),
additionalProperties: false
}
}]
},
else: {
type: 'object',
if: {
properties: bundleBuildConfigProperties
},
then: {
properties: _objectSpread(_objectSpread({}, bundleBuildConfigProperties), commonBuildConfigProperties),
additionalProperties: false
},
else: {
properties: _objectSpread(_objectSpread({}, bundlelessBuildConfigProperties), commonBuildConfigProperties),
additionalProperties: false
}
}
}
};
exports.buildConfig = buildConfig;
const buildPreset = {
target: 'buildPreset',
schema: {
if: {
type: 'string'
},
then: {
enum: presets
},
else: {
typeof: 'function'
}
}
};
exports.buildPreset = buildPreset;
const schema = [source, buildConfig, buildPreset];
exports.schema = schema;
//# sourceMappingURL=schema.js.map