const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const env = process.env

module.exports = {
    entry: {
        main : "./main.js",
        vendors: ['jquery', 'rem', 'vue'],
    },
    output: {
    },
    resolve: {
        extensions: ['.js', '.vue', '.scss'],
        alias: {
            "vue": 'vue/dist/vue.esm.js',
            "rem": path.resolve(__dirname, './depend/rem/rem.js'),
            "popup": path.resolve(__dirname, './depend/artDialog/popup.js'),
            "dialog-config": path.resolve(__dirname, './depend/artDialog/dialog-config.js'),
            "form": path.resolve(__dirname, './depend/form/form.js'),
            "md5": path.resolve(__dirname, './depend/md5/md5.js'),
            "template": path.resolve(__dirname, './depend/artTemplate/template.js'),
            "cookie": path.resolve(__dirname, './depend/cookie/cookie.js'),
            "store": path.resolve(__dirname, './depend/store/store.js'),
            "jweixin": path.resolve(__dirname, './depend/jweixin/jweixin-1.0.0.js'),
            "lib": path.resolve(__dirname, './depend/lib/lib.js'),
            "BDY": path.resolve(__dirname, './depend/BDY/BDY.js'),
            "lrz": path.resolve(__dirname, './depend/localResizeIMG/lrz.all.bundle.js'),
            "nprogress": path.resolve(__dirname, './depend/nprogress/nprogress.js'),
            "extSdk": path.resolve(__dirname, './depend/extSdk/extSdk.js'),
            "swiper": path.resolve(__dirname, './depend/swiper/swiper-3.4.2.jquery.min.js'),
            "lazyload": path.resolve(__dirname, './depend/lazyload/jquery.lazyload.js')
        }
    },
    module: {
        rules: [{ 
            test: /\.js$/,
            exclude: /(node_modules|bower_components)/,
            use: {
                loader : 'babel-loader',
                options : {
                    presets : ['es2015']
                }
            }
        },{
            test: /\.vue$/,
            loader: 'vue-loader',
            options: {
                loaders: {
                    css: ExtractTextPlugin.extract({
                        fallback: "vue-style-loader",
                        use: "css-loader",
                        publicPath: './'
                    }),
                    scss: ExtractTextPlugin.extract({
                        fallback: "vue-style-loader",
                        use: "sass-loader",
                        publicPath: './'
                    })
                }
            }
        },{
            test: /\.css$/,
            use: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: "css-loader",
                publicPath: './'
            })
        },{
            test: /\.scss$/,
            use: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: [{
                    loader: "css-loader",
                    options: {
                        minimize: env.npm_lifecycle_event === 'build' ? true : false
                    }
                }, {
                    loader: "sass-loader"
                }],
                publicPath: './'
            })
        },{
            test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
            use: 'url-loader?limit=50000'
        },{ 
            test: /\.(html|tpl)$/, 
            use: 'html-loader' 
        },{
            test: /\.json$/,
            use: 'json-loader'
        }]
    },
    // babel: {
    //     presets: ['es2015']
    // },
    plugins: [
        new webpack.optimize.ModuleConcatenationPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.LoaderOptionsPlugin({
            minimize: true
        })
    ]
    // extraPath: "../"

};
