const webpack = require('webpack');
const merge = require('webpack-merge');
const path = require('path');
const base = require('./webpack.base.config');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
// const BabelMinifyPlugin = require("babel-minify-webpack-plugin");

let output = {
    path : path.resolve(__dirname, `./build`),
    publicPath : `build/`,
    filename : 'bundle/[name].bundle.js?[hash]',
    chunkFilename : 'chunk/[name].chunk.js?[hash]'
}

// config.output.path = config.extraPath + '/build';
// config.output.publicPath = 'build/';
// config.output.filename = '[name].js?[hash]';
// config.output.chunkFilename = '[name].chunk.js?[hash]';

// config.vue = {
//     loaders : {
//         css: ExtractTextPlugin.extract(
//             "style-loader",
//             "css-loader?sourceMap",
//             {
//                 publicPath: './',
//             }
//         ),
//         less: ExtractTextPlugin.extract(
//             'vue-style-loader',
//             'css-loader!less-loader'
//         ),
//         sass: ExtractTextPlugin.extract(
//             'vue-style-loader',
//             'css-loader!sass-loader',
//             {
//                 publicPath: './',
//             }
//         )
//     }
// }

// config.plugins = (config.plugins || []).concat([
//     new ExtractTextPlugin("[name].css?[hash]",{ allChunks : false, resolve : ['modules'] }),
//     new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js?[hash]'),
//     new webpack.DefinePlugin({
//         'process.env': {
//             NODE_ENV: '"production"'
//         }
//     }),
//     new webpack.optimize.UglifyJsPlugin({
//         compress: {
//             warnings: false
//         }
//     }),
//     new HtmlWebpackPlugin({
//         filename: '../index.html',
//         template: './index.ejs',
//         inject: false
//     }),
//     new webpack.ProvidePlugin({
//         $: "jquery",
//         jQuery: "jquery",
//         "window.jQuery": "jquery"
//     })
// ]);

let plugins = [
    new ExtractTextPlugin("style/[name].css?[hash]",{
        allChunks : true,
        resolve : ['modules']
    }),
    new webpack.optimize.CommonsChunkPlugin({
        name : 'vendors',
        filename : 'chunk/vendors.chunk.js?[hash]'
    }),
    new webpack.DefinePlugin({
        'process.env': {
            NODE_ENV: JSON.stringify("production")
        }
    }),
    new UglifyJSPlugin({
        uglifyOptions: {
            compress: {
                warnings: false
            }
        },
        parallel: true
    }),
    // new BabelMinifyPlugin(),
    new HtmlWebpackPlugin({
        filename: './index.html',
        template: './index.ejs',
        inject: 'body',
        // chunks: ['main','vendors'],
        minify: {
            html5: false,
            removeComments: true,
            removeEmptyAttributes: true,
            collapseWhitespace: true
        }
    }),
    new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery"
    })
]

module.exports = merge(base, {
    // devtool: 'source-map',
    output: output,
    plugins: plugins
});
