// const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const fs = require('fs');

const appDirectory = fs.realpathSync(process.cwd());

// const isDev = process.env.NODE_ENV === 'development';
// const cssFilename = 'static/css/[name].[contenthash:8].css';
// const cssClassName = isDev ? '[path][name]__[local]--[hash:base64:5]' : '[hash:base64:5]';
// const extractLess = new ExtractTextPlugin({
// 	filename: cssFilename,
// 	disable: isDev
// });
module.exports = (config, env, defaultConfig) => {
	defaultConfig.externals = {
		jsdom: 'window',
		cheerio: 'window',
		'react/lib/ExecutionEnvironment': true,
		'react/lib/ReactContext': 'window',
		'react/addons': true
	};

	defaultConfig.module.rules.push({
		test: /\.less$/,
		use: [
			{
				loader: 'style-loader'
			},
			{
				loader: 'css-loader',
				options: {
					modules: true,
					localIdentName: '[local]',
				}
			},
			{
				loader: 'less-loader'
			},
		],
		include: path.resolve(__dirname, '../'),
		exclude: path.resolve(__dirname, '../components'),
	},
	{
		test: /\.less$/,
		use: [
			{
				loader: 'style-loader'
			},
			{
				loader: 'css-loader',
				options: {
					modules: true,
					localIdentName: 'pp-[local]-[hash:base64:6]',
				}
			},
			{
				loader: 'less-loader'
			},
		],
		include: path.resolve(__dirname, '../components'),
	});

	// defaultConfig.plugins.push(extractLess);

	defaultConfig.resolve.alias = {
		'../../theme.config$': path.resolve(appDirectory, 'styling/theme.config'),
		heading: path.resolve(appDirectory, 'styling/heading.less'),
	};
	return defaultConfig;
};
