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 = {};
|
2020-05-20 22:05:52 +05:30
|
|
|
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')),
|
|
|
|
},
|
2021-03-26 08:49:04 +05:30
|
|
|
'postcss-bidirection': {},
|
2020-05-24 04:38:24 +05:30
|
|
|
// 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-11-27 14:33:32 +05:30
|
|
|
},
|
2019-07-01 09:09:59 +05:30
|
|
|
});
|