All files / tasks/util postcss.ts

100% Statements 15/15
100% Branches 4/4
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3643x 43x 43x 43x 43x 43x 43x   134x 91x                             3x 3x 3x 3x 3x              
const path = require('path');
const fs = require('fs');
const cssNano = require('cssnano');
const postCssImport = require('postcss-import');
const postCssNext = require('postcss-cssnext');
const postCssModules = require('postcss-modules');
const umdWrapper = require('./umdWrapper');
 
export function createProcessors(dest: string, cwd = '', dist?: boolean) {
	return [
		postCssImport,
		postCssNext({
			features: {
				autoprefixer: {
					browsers: [
						'last 2 versions',
						'ie >= 11'
					]
				}
			}
		}),
		postCssModules({
			generateScopedName: dist ? '[hash:base64:8]' : '[name]__[local]__[hash:base64:5]',
			getJSON: function(cssFileName: string, json: any) {
				const outputPath = path.resolve(dest, path.relative(cwd, cssFileName));
				const newFilePath = outputPath + '.js';
				const themeKey = ' _key';
				json[themeKey] = 'dojo-' + path.basename(outputPath, '.m.css');
				fs.writeFileSync(newFilePath, umdWrapper(JSON.stringify(json)));
			}
		}),
		// autoprefixer included in cssnext
		cssNano({ autoprefixer: false })
	];
};