accounts-frontend/postcss.config.js

71 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-12-07 16:58:52 +05:30
/* eslint-disable @typescript-eslint/no-var-requires */
2019-07-01 09:09:59 +05:30
/* eslint-env node */
const path = require('path');
const loaderUtils = require('loader-utils');
const fileCache = {};
const isProduction = process.argv.some((arg) => arg === '-p');
2019-07-01 09:09:59 +05:30
const rootPath = path.resolve('./src');
module.exports = ({ webpack: loader }) => ({
2020-05-24 04:38:24 +05:30
syntax: 'postcss-scss',
plugins: {
'postcss-import': {
addModulesDirectories: ['./src'],
2019-07-01 09:09:59 +05:30
2020-05-24 04:38:24 +05:30
resolve: ((defaultResolve) => (url, basedir, importOptions) =>
defaultResolve(
// mainly to remove '~' from request
loaderUtils.urlToRequest(url),
basedir,
importOptions,
))(require('postcss-import/lib/resolve-id')),
2019-07-01 09:09:59 +05:30
2020-05-24 04:38:24 +05:30
load: ((defaultLoad) => (filename, importOptions) => {
if (/\.font.(js|json)$/.test(filename)) {
// separately process calls to font loader
// e.g. `@import '~app/icons.font.json';`
if (!fileCache[filename] || !isProduction) {
// do not execute loader on the same file twice
// this is an overcome for a bug with ExtractTextPlugin, for isProduction === true
// when @imported files may be processed multiple times
fileCache[filename] = new Promise((resolve, reject) =>
loader.loadModule(filename, (err, source) => {
if (err) {
reject(err);
2019-07-01 09:09:59 +05:30
2020-05-24 04:38:24 +05:30
return;
}
2019-07-01 09:09:59 +05:30
2020-05-24 04:38:24 +05:30
resolve(loader.exec(source, rootPath));
}),
);
}
2019-07-01 09:09:59 +05:30
2020-05-24 04:38:24 +05:30
return fileCache[filename];
}
2019-07-01 09:09:59 +05:30
2020-05-24 04:38:24 +05:30
return defaultLoad(filename, importOptions);
})(require('postcss-import/lib/load-content')),
},
// TODO: for some reason cssnano strips out @mixin declarations
// cssnano: {
// /**
// * TODO: cssnano options
// */
// // autoprefixer: {
// // add: true,
// // remove: true,
// // browsers: ['last 2 versions']
// // },
// // safe: true,
// // // отключаем минификацию цветов, что бы она не ломала такие выражения:
// // // composes: black from '~./buttons.scss';
// // colormin: false,
// // discardComments: {
// // removeAll: true
// // }
// preset: 'default'
// }
},
2019-07-01 09:09:59 +05:30
});