/**
 * Created by fendy on 2017/6/8.
 */
let config = require('./config');
let webpack = require('webpack');
let ExtractText = require('extract-text-webpack-plugin');
let path = require('path');
let FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');

module.exports = {
    entry: {
        app: config.entry,
        vendors: ['vue', 'vuex', 'vue-router', 'axios', 'iview']
    },
    output: {
        filename: 'js/[name].js',
        path: config.output,
	    chunkFilename: 'modules/[name].js',
        publicPath: '/assert/'
    },
    devtool: 'cheap-module-source-map',
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {
                    loaders: {
                        scss: 'vue-style-loader!css-loader!sass-loader'
                    }
                }
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                use: ExtractText.extract({
                    fallback: 'style-loader',
                    use: 'css-loader'
                })
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: 'img/[name].[hash:7].[ext]'
                }
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: 'font/[name].[hash:7].[ext]'
                }
            }
        ]
    },
    resolve: {
        extensions: [' ', '.js', '.vue'],
        alias: {
            'vue$': 'vue/dist/vue.esm.js',
            '@': path.join(__dirname, '..', 'public'),
            'modules': path.join(__dirname, '..', 'public/modules')
        }
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"development"'
            }
        }),
        new ExtractText('styles.css'),
        new webpack.NoEmitOnErrorsPlugin(),
        new FriendlyErrorsPlugin(),
        new webpack.optimize.CommonsChunkPlugin({name: 'manifest', chunks: ['vendor']})
    ]
};