'use strict';
const path = require('path');
const resolve = function (src) {
    return path.resolve(__dirname, src);
};
const config = require('../config');
const utils = require('./utils');
const env = process.env.NODE_ENV;


const urlPath = env === 'production' ? utils.assetsPath('img/[name].[hash:7].[ext]') : "img/[name].[hash:7].[ext]";
const fontPath = env === 'production' ? utils.assetsPath('font/[name].[hash:7].[ext]') : "font/[name].[hash:7].[ext]";

module.exports = {
    entry: {
        main:['./src/main.js']
    },// 配置需要打包的入口文件
    output: {
        path: config.build.assetsRoot,// 输出文件根目录
        filename: '[name].js',//输出文件路径和名字
        publicPath: env === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath
    },
    resolve: {
        extensions: [".js",'.jsx',".json"],
        alias: {
            '@': resolve('../src'),
            '@src': resolve('../src'),
            '@common': resolve('../src/common'),
            '@commonComp': resolve('../src/common/components'),
            '@less': resolve('../src/common/less'),
            '@mixin': resolve('../src/common/less/mixin.less'),
            '@images': resolve('../src/common/images'),
            '@components': resolve('../src/components'),
            '@containers': resolve('../src/containers'),
            '@modules': resolve('../src/module'),
            '@mock': resolve('../src/mock/'),
            '@utils': resolve('../src/utils'),
            '@lib': resolve('../src/lib'),
            '@store':  resolve('../src/store'),
            '@asyncActions':  resolve('../src/store/async-actions'),
            '@actions':  resolve('../src/store/actions'),
            '@reducers':  resolve('../src/store/reducers'),
            '@types':  resolve('../src/store/types'),
            '@config':resolve('../src/config')
        }
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 8196,
                    publicPath: '../../',
                    name:urlPath,
                }
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                loader: 'url-loader',
                options: {
                    limit: 8196,
                    publicPath: '../../',
                    name:fontPath,
                }
            }
        ]
    }
};