'use strict'
const baseWebpackConfig = require('./webpack.base.conf')
const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const merge = require('webpack-merge')
// const ExtractTextPlugin = require('extract-text-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')

const faster = process.env.MODE === 'faster'
const output = process.env.OUTPUT || resolve('static')

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

delete baseWebpackConfig.entry
delete baseWebpackConfig.optimization.splitChunks
const webpackConfig = merge(baseWebpackConfig, {
  mode: 'production',
  devtool: false,
  entry: {
    dll: [
      './src/common/util.js',
      './src/common/privilege.js',
      './src/mixins/emitter.js',
      './src/pages/common/zcmsComponents.js'
    ]
  },
  output: {
    path: output,
    filename: 'zcms.dll.js', // 输出动态连接库的文件名称
    library: '_dll_library' // 全局变量名称
  },
  optimization: {
  },
  plugins: [
    new CaseSensitivePathsPlugin(),
    new VueLoaderPlugin(),
    // http://vuejs.github.io/vue-loader/en/workflow/production.html
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('production')
    }),
    // extract css into its own file
    // new ExtractTextPlugin({
    //   filename: 'assets/css/[name].[chunkhash:6].css',
    //   allChunks: true
    // }),
    // keep module.id stable when vendor modules does not change
    new webpack.HashedModuleIdsPlugin(),
    // enable scope hoisting
    new webpack.optimize.ModuleConcatenationPlugin(),
    new webpack.DllPlugin({
      name: '_dll_library',
      path: path.join(__dirname, '../static/dll-manifest.json')
    })
  ]
})
if (faster) {
  webpackConfig.optimization.minimizer = []
} else {
  webpackConfig.optimization.minimizer = [
    new UglifyJsPlugin({
      uglifyOptions: {
        compress: {
          warnings: false
        }
      },
      sourceMap: true,
      parallel: true
    })
  ]
}

module.exports = webpackConfig
