const webpack = require('webpack');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const cwd = process.cwd();
const dist = path.join(cwd, 'dist');
const isProductionBuild = process.env.NODE_ENV === 'production';

const jsLoaders = [
  {
    loader: require.resolve('babel-loader'),
    options: require('../babel/babel.config')
  }
];

const cssLoaders = [
  {
    loader: require.resolve('css-loader'),
    options: {
      modules: true,
      minimize: isProductionBuild
    }
  },
  {
    loader: require.resolve('less-loader')
  }
];

const svgLoaders = [
  {
    loader: require.resolve('raw-loader')
  },
  {
    loader: require.resolve('svgo-loader'),
    options: {
      plugins: [
        {
          addAttributesToSVGElement: {
            attribute: 'focusable="false"'
          }
        }
      ]
    }
  }
];

module.exports = [
  {
    entry: path.join(cwd, 'src/index.js'),
    output: {
      path: dist,
      filename: '[name].js'
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules\/(?!(seek-style-guide)\/).*/,
          use: jsLoaders
        },
        {
          test: /\.less$/,
          use: ExtractTextPlugin.extract({
            fallback: 'style-loader',
            use: cssLoaders
          })
        },
        {
          test: /\.svg$/,
          use: svgLoaders
        }
      ]
    },
    plugins: [
      new ExtractTextPlugin('style.css')
    ].concat(!isProductionBuild ? [] : [
      new webpack.optimize.UglifyJsPlugin(),
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
      })
    ])
  },
  {
    entry: {
      render: path.join(cwd, 'src/render.js')
    },
    output: {
      path: dist,
      filename: '[name].js',
      libraryTarget: 'umd'
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules\/(?!(seek-style-guide)\/).*/,
          use: jsLoaders
        },
        {
          test: /\.less$/,
          use: cssLoaders
        },
        {
          test: /\.svg$/,
          use: svgLoaders
        }
      ]
    },
    plugins: [
      new StaticSiteGeneratorPlugin('render', '/')
    ]
  }
];

@@ -245,16 +245,20 @@
 nst dist
+Path
  = path.
@@ -272,24 +272,96 @@
 d, 'dist');%0A
+const styleGuidePath = path.join(cwd, 'node_modules/seek-style-guide');%0A
 const isProd
@@ -543,17 +543,21 @@
 %0A%0Aconst 
-c
+makeC
 ssLoader
@@ -552,38 +552,231 @@
 akeCssLoaders = 
-%5B%0A  %7B%0A
+(options = %7B%7D) =%3E %7B%0A  const %7B%0A    styleGuide = false%0A  %7D = options;%0A%0A  const debugIdent = isProductionBuild ? '' :%0A    %60$%7BstyleGuide ? '__STYLE_GUIDE__' : ''%7D%5Bname%5D__%5Blocal%5D___%60;%0A%0A  return %5B%0A    %7B%0A  
     loader: requ
@@ -798,32 +798,34 @@
 s-loader'),%0A    
+  
 options: %7B%0A     
@@ -815,24 +815,26 @@
  options: %7B%0A
+  
       module
@@ -842,16 +842,74 @@
 : true,%0A
+        localIdentName: %60$%7BdebugIdent%7D%5Bhash:base64:7%5D%60,%0A  
       mi
@@ -942,23 +942,29 @@
     
-%7D%0A
+  %7D%0A  
   %7D,%0A
+  
   %7B%0A    
 load
@@ -951,32 +951,34 @@
    %7D,%0A    %7B%0A    
+ 
+ 
 loader: require.
@@ -998,27 +998,34 @@
 -loader')%0A  
-%7D%0A%5D
+  %7D%0A  %5D;%0A%7D
 ;%0A%0Aconst svg
@@ -1391,32 +1391,36 @@
       path: dist
+Path
 ,%0A      filename
@@ -1632,32 +1632,67 @@
 est: /%5C.less$/,%0A
+          exclude: /node_modules/,%0A
           use: E
@@ -1769,34 +1769,271 @@
        use: 
-cssLoaders
+makeCssLoaders()%0A          %7D)%0A        %7D,%0A        %7B%0A          test: /%5C.less$/,%0A          include: styleGuidePath,%0A          use: ExtractTextPlugin.extract(%7B%0A            fallback: 'style-loader',%0A            use: makeCssLoaders(%7B styleGuide: true %7D)
 %0A          %7D
@@ -2497,16 +2497,20 @@
 th: dist
+Path
 ,%0A      
@@ -2780,23 +2780,199 @@
     
-use: cssLoaders
+exclude: /node_modules/,%0A          use: makeCssLoaders()%0A        %7D,%0A        %7B%0A          test: /%5C.less$/,%0A          include: styleGuidePath,%0A          use: makeCssLoaders(%7B styleGuide: true %7D)
 %0A   

Allow debugging of CSS classes in development