'use strict'

import vueLoaderConfig from './vue-loader.config'
import { defaults } from 'lodash'
import { join } from 'path'
import { isUrl, urlJoin } from '../utils'

/*
|--------------------------------------------------------------------------
| Webpack Shared Config
|
| This is the config which is extended by the server and client
| webpack config files
|--------------------------------------------------------------------------
*/
export default function ({ isClient, isServer }) {
  const nodeModulesDir = join(__dirname, '..', 'node_modules')
  let config = {
    devtool: (this.dev ? 'cheap-module-eval-source-map' : false),
    entry: {
      vendor: ['vue', 'vue-router', 'vue-meta']
    },
    output: {
      publicPath: (isUrl(this.options.build.publicPath) ? this.options.build.publicPath : urlJoin(this.options.router.base, this.options.build.publicPath))
    },
    performance: {
      maxEntrypointSize: 300000,
      maxAssetSize: 300000,
      hints: (this.dev ? false : 'warning')
    },
    resolve: {
      extensions: ['.js', '.json', '.vue'],
      // Disable for now
      alias: {
        '~': join(this.srcDir),
        'static': join(this.srcDir, 'static'), // use in template with <img src="~static/nuxt.png" />
        '~static': join(this.srcDir, 'static'),
        'assets': join(this.srcDir, 'assets'), // use in template with <img src="~static/nuxt.png" />
        '~assets': join(this.srcDir, 'assets'),
        '~plugins': join(this.srcDir, 'plugins'),
        '~store': join(this.dir, '.nuxt/store'),
        '~router': join(this.dir, '.nuxt/router'),
        '~pages': join(this.srcDir, 'pages'),
        '~components': join(this.srcDir, 'components')
      },
      modules: [
        nodeModulesDir,
        join(this.dir, 'node_modules')
      ]
    },
    resolveLoader: {
      modules: [
        nodeModulesDir,
        join(this.dir, 'node_modules')
      ]
    },
    module: {
      rules: [
        {
          test: /\.vue$/,
          loader: 'vue-loader',
          query: vueLoaderConfig.call(this, { isClient, isServer })
        },
        {
          test: /\.js$/,
          loader: 'babel-loader',
          exclude: /node_modules/,
          query: defaults(this.options.build.babel, {
            presets: ['vue-app'],
            cacheDirectory: !!this.dev
          })
        },
        {
          test: /\.css$/,
          loader: 'vue-style-loader!css-loader'
        }
      ]
    },
    plugins: this.options.build.plugins
  }
  // Add nuxt build loaders (can be configured in nuxt.config.js)
  config.module.rules = config.module.rules.concat(this.options.build.loaders)
  // Return config
  return config
}

@@ -2344,34 +2344,90 @@
 %7D,%0A        %7B
-%0A
  
+test: /%5C.css$/, loader: 'vue-style-loader!css-loader' %7D,%0A
         
  test: /%5C.cs
@@ -2406,32 +2406,33 @@
 der' %7D,%0A        
+%7B
  test: /%5C.css$/,
@@ -2429,24 +2429,190 @@
  /%5C.
-css$/,%0A         
+less$/, loader: 'vue-style-loader!css-loader!less-loader' %7D,%0A        %7B test: /%5C.sass$/, loader: 'vue-style-loader!css-loader!sass-loader?indentedSyntax' %7D,%0A        %7B test: /%5C.scss$/,
  loa
@@ -2648,17 +2648,32 @@
 ader
+!sass-loader
 '
+ %7D,
 %0A       
  %7D%0A 
@@ -2668,16 +2668,92 @@
 %0A       
+ %7B test: /%5C.styl(us)?$/, loader: 'vue-style-loader!css-loader!stylus-loader'
  %7D%0A     

Add common pre-processors in nuxt