@modern-js/module-tools-v2
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
81 lines (80 loc) • 4.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getStyleConfig = exports.getSassConfig = exports.getPostcssConfig = exports.getLessConfig = void 0;
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 getLessConfig = async config => {
var _config$tools;
const {
applyOptionsChain
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils')));
const {
getCompiledPath
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./path")));
const mergedOptions = applyOptionsChain({
lessOptions: {
javascriptEnabled: true
},
implementation: getCompiledPath('less')
}, (config === null || config === void 0 ? void 0 : (_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.less) || {});
return mergedOptions;
};
exports.getLessConfig = getLessConfig;
const getSassConfig = async config => {
var _config$tools2;
const {
applyOptionsChain
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils')));
const {
getCompiledPath
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./path")));
const mergedOptions = applyOptionsChain({
implementation: getCompiledPath('sass')
}, ((_config$tools2 = config.tools) === null || _config$tools2 === void 0 ? void 0 : _config$tools2.sass) || {});
return mergedOptions;
};
exports.getSassConfig = getSassConfig;
const getPostcssConfig = async config => {
var _config$tools3;
const {
applyOptionsChain
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/utils')));
const {
getCompiledPath
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./path")));
const extraPlugins = [];
const utils = {
addPlugins(plugins) {
if (Array.isArray(plugins)) {
extraPlugins.push(...plugins);
} else {
extraPlugins.push(plugins);
}
}
};
const mergedConfig = applyOptionsChain({
// TODO: when schema support redefine
// $$tools: 'module-tools',
plugins: [require(getCompiledPath('postcss-flexbugs-fixes')), require(getCompiledPath('postcss-custom-properties')), require(getCompiledPath('postcss-initial')), require(getCompiledPath('postcss-page-break')), require(getCompiledPath('postcss-font-variant')), require(getCompiledPath('postcss-media-minmax')), require(getCompiledPath('postcss-nesting'))].filter(Boolean)
}, (config === null || config === void 0 ? void 0 : (_config$tools3 = config.tools) === null || _config$tools3 === void 0 ? void 0 : _config$tools3.postcss) || {}, utils);
if (extraPlugins.length) {
mergedConfig.plugins.push(...extraPlugins);
}
return mergedConfig;
};
exports.getPostcssConfig = getPostcssConfig;
const getStyleConfig = async api => {
const config = api.useResolvedConfigContext();
const postcssConfig = await getPostcssConfig(config);
const lessConfig = await getLessConfig(config);
const sassConfig = await getSassConfig(config);
return {
less: lessConfig,
sass: sassConfig,
postcss: postcssConfig
};
};
exports.getStyleConfig = getStyleConfig;
//# sourceMappingURL=style.js.map