Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolvePreset(preset) {
let fn, options;
if (Array.isArray(preset)) {
fn = preset[0];
options = preset[1];
} else {
fn = preset;
options = {};
}
// For JS setups where we invoked the preset already
if (preset.plugins) {
return Promise.resolve(preset.plugins);
}
// Provide an alias for the default preset, as it is built-in.
if (fn === 'default') {
return Promise.resolve(require('cssnano-preset-default')(options).plugins);
}
// For non-JS setups; we'll need to invoke the preset ourselves.
if (typeof fn === 'function') {
return Promise.resolve(fn(options).plugins);
}
// Try loading a preset from node_modules
if ((0, _isResolvable2.default)(fn)) {
return Promise.resolve(require(fn)(options).plugins);
}
const sugar = `cssnano-preset-${fn}`;
// Try loading a preset from node_modules (sugar)
if ((0, _isResolvable2.default)(sugar)) {
return Promise.resolve(require(sugar)(options).plugins);
}
// If all else fails, we probably have a typo in the config somewhere
throw new Error(`Cannot load preset "${fn}". Please check your configuration for errors and try again.`);
function resolvePreset(preset) {
let fn, options;
if (Array.isArray(preset)) {
fn = preset[0];
options = preset[1];
} else {
fn = preset;
options = {};
}
// For JS setups where we invoked the preset already
if (preset.plugins) {
return Promise.resolve(preset.plugins);
}
// Provide an alias for the default preset, as it is built-in.
if (fn === 'default') {
return Promise.resolve(require('cssnano-preset-default')(options).plugins);
}
// For non-JS setups; we'll need to invoke the preset ourselves.
if (typeof fn === 'function') {
return Promise.resolve(fn(options).plugins);
}
// Try loading a preset from node_modules
if ((0, _isResolvable2.default)(fn)) {
return Promise.resolve(require(fn)(options).plugins);
}
const sugar = `cssnano-preset-${fn}`;
// Try loading a preset from node_modules (sugar)
if ((0, _isResolvable2.default)(sugar)) {
return Promise.resolve(require(sugar)(options).plugins);
}
// If all else fails, we probably have a typo in the config somewhere
throw new Error(`Cannot load preset "${fn}". Please check your configuration for errors and try again.`);
[require('postcss-bidirection'), {
buildSelector: function (selector, direction) {
return `[dir="${direction}"] ${selector}`
}
}],
[require('autoprefixer'), { overrideBrowserslist: loadConfig('browserslist', require('@instructure/browserslist-config-instui')) }],
[require('postcss-initial')],
[require('postcss-reporter'), { clearReportedMessages: true }]
]
// For production builds we need to minify css with postcss here, we can't rely on babel/uglify to
// minify the css part of our js bundles because by the time they see it is just a string.
if ((process.env.BABEL_ENV || process.env.NODE_ENV) === 'production') {
// we can't just use all of cssnano because there are some things it does that won't work for us,
// so we filter them out.
const minificationPlugins = require('cssnano-preset-default')({
svgo: {'doesn\'t work': true}, // only has an async api and the css modules require hook needs everything to have a sync api
convertValues: {'doesn\'t work': true}, // needs postcss 7+, when css-modules-require-hook uses 7.x, it should work
mergeLonghand: {'doesn\'t work': true} // needs postcss 7+, when css-modules-require-hook uses 7.x, it should work
}).plugins.filter(([_, pluginOpts = {}]) => !pluginOpts['doesn\'t work'])
CORE_PLUGINS_POST.push(...minificationPlugins)
}
module.exports = function (opts = { before: {}, after: {}, nesting: false }) {
return function (ctx = {}) {
let plugins = [
...CORE_PLUGINS_PRE,
opts.nesting ? [require('postcss-nesting')] : [require('postcss-nested')],
...CORE_PLUGINS_POST
]