const webpack = require('webpack')
// 引入基本配置
const baseConfig = require('./webpack.base')
// 引入 webpack 配置合并插件
const { merge } = require('webpack-merge')
// 引入 path 模块
const path = require('path')
// 解析.vue文件
// const VueLoaderPlugin = require('vue-loader/lib/plugin')
const { VueLoaderPlugin } = require('vue-loader')
// 热更新插件
const HtmlWebpackPlugin = require('html-webpack-plugin')

const config = {
    mode: 'development',
    entry: path.resolve(__dirname, '../test/index.js'),
    devServer: {
        hot: true,
        // 启动后是否默认打开浏览器
        open: true,
        // 在浏览器上全屏显示编译的errors或warnings
        client: {
            overlay: {
                warnings: false,
                errors: true
            }
        },
        headers: {
            // 确保 主项目能fetch 避免跨域
            "Access-Control-Allow-Origin": "*"
        },
        // 代理配置
        proxy: {
            // 后端API代理
            "/api": {
                // target: 'https://www.easy-mock.com/mock/5e6342597bd3ba143d8b5374/api',
                // target: 'https://101.133.164.217:8285/stage-api',
                target: "http://114.67.82.17/stage-api",
                // target: 'http://192.168.2.33:8081',
                changeOrigin: true,
                ws: true,
                https: true,
                pathRewrite: {
                    "^/api": ""
                }
            },
            // 上传文件后，访问文件的代理
            "/files": {
                // target: 'https://www.easy-mock.com/mock/5e6342597bd3ba143d8b5374/api',
                target: "http://101.133.164.217/files",
                changeOrigin: true,
                pathRewrite: {
                    "^/files": ""
                }
            }
        }
    },
    plugins: [
        new VueLoaderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new HtmlWebpackPlugin({
            template: 'test/index.html',
            filename: 'index.html'
        })
    ]
}

module.exports = merge(config, baseConfig)
