var path = require('path')
var config = require('../config')
var utils = require('./utils')
var webpack = require('webpack')
var merge = require('webpack-merge')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
var env = process.env.NODE_ENV === 'testing'
  ? require('../config/test.env')
  : config.build.env

var baseWebpackConfig = merge(require('./webpack.base.conf'), {
  entry: {
    'vuikit': './src/lib/'
  },
  externals: {
    vue: 'vue'
  },
  module: {
    loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
  },
  vue: {
    loaders: utils.cssLoaders({
      sourceMap: config.build.productionSourceMap,
      extract: true
    })
  },
  plugins: [
    new LodashModuleReplacementPlugin({
      'collections': true
    }),
    // http://vuejs.github.io/vue-loader/workflow/production.html
    new webpack.DefinePlugin({
      'process.env': env
    }),
    // makes lodash even smaller
    new LodashModuleReplacementPlugin,
    // not sure why, but necessary
    new webpack.optimize.OccurenceOrderPlugin(),
    // extract css into its own file
    new ExtractTextPlugin(utils.assetsPath('[name].css')),
    // add banner on top of each file
    new webpack.BannerPlugin(config.build.banner, {
      raw: true,
      entryOnly: true
    }),
    // workaround to exclude moment.js locales
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  ]
})

module.exports = [
  // dist
  merge({}, baseWebpackConfig, {
    output: {
      path: 'dist',
      filename: '[name].js',
      chunkFilename: '[id].js'
    },
    devtool: config.build.productionSourceMap ? '#source-map' : false,
    plugins: [
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      })
    ]
  }),
  // dist common
  merge({}, baseWebpackConfig, {
    output: {
      path: 'dist',
      filename: '[name].common.js',
      chunkFilename: '[id].common.js',
      library: 'Vuikit',
      libraryTarget: 'commonjs2'
    },
    devtool: false,
  })
]

var path = require('path')
var config = require('../config')
var utils = require('./utils')
var webpack = require('webpack')
var merge = require('webpack-merge')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
var env = process.env.NODE_ENV === 'testing'
  ? require('../config/test.env')
  : config.build.env

var baseWebpackConfig = merge(require('./webpack.base.conf'), {
  entry: {
    'vuikit': './src/lib/'
  },
  externals: {
    vue: 'vue'
  },
  module: {
    loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
  },
  vue: {
    loaders: utils.cssLoaders({
      sourceMap: config.build.productionSourceMap,
      extract: true
    })
  },
  plugins: [
    new LodashModuleReplacementPlugin({
      'collections': true
    }),
    // makes lodash even smaller
    new LodashModuleReplacementPlugin,
    // not sure why, but necessary
    new webpack.optimize.OccurenceOrderPlugin(),
    // extract css into its own file
    new ExtractTextPlugin(utils.assetsPath('[name].css')),
    // add banner on top of each file
    new webpack.BannerPlugin(config.build.banner, {
      raw: true,
      entryOnly: true
    }),
    // workaround to exclude moment.js locales
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  ]
})

module.exports = [
  // dist
  merge({}, baseWebpackConfig, {
    output: {
      path: 'dist',
      filename: '[name].js',
      chunkFilename: '[id].js'
    },
    devtool: config.build.productionSourceMap ? '#source-map' : false,
    plugins: [
      // http://vuejs.github.io/vue-loader/workflow/production.html
      new webpack.DefinePlugin({
        'process.env': env
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      })
    ]
  }),
  // dist common
  merge({}, baseWebpackConfig, {
    output: {
      path: 'dist',
      filename: '[name].common.js',
      chunkFilename: '[id].common.js',
      library: 'Vuikit',
      libraryTarget: 'commonjs2'
    },
    devtool: false,
  })
]

fix dist build