"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const dotenv_flow_webpack_1 = tslib_1.__importDefault(require("dotenv-flow-webpack"));
const dotenv_flow_1 = require("dotenv-flow");
const compression_webpack_plugin_1 = tslib_1.__importDefault(require("compression-webpack-plugin"));
const path_1 = tslib_1.__importDefault(require("path"));
dotenv_flow_1.config({ silent: true });
const definitions = new dotenv_flow_webpack_1.default().definitions;
for (const key in definitions) {
    definitions[key] = definitions[key].substr(1);
    definitions[key] = definitions[key].substr(0, definitions[key].length - 1);
}
delete definitions['process.env.MASTER_KEY'];
delete definitions['process.env.ADMIN_USERNAME'];
delete definitions['process.env.ADMIN_PASSWORD'];
delete definitions['process.env.ADMIN_PHONE_NUMBER'];
delete definitions['process.env.DATABASE_PORT'];
delete definitions['process.env.DATABASE_HOST'];
delete definitions['process.env.DATABASE_USER'];
delete definitions['process.env.DATABASE_NAME'];
delete definitions['process.env.DATABASE_PASS'];
exports.default = (extraOptions) => Object.assign({
    nodeModulesTransform: {
        type: 'none',
    },
    dynamicImport: {
        loading: '@wxsoft/wxcomponents/lib/WxDynamicLoading',
    },
    publicPath: '/public/',
    proxy: {
        ['/' + definitions['process.env.APP_NAME']]: {
            target: `http://localhost:${process.env.WXEAP_PORT}`,
            changeOrigin: true,
        },
    },
    define: {
        ...definitions,
    },
    chainWebpack(memo) {
        // 设置 alias
        memo.resolve.alias.set('@server', path_1.default.join(process.cwd(), 'server'));
        memo.resolve.alias.set('@wxeap', path_1.default.join(process.cwd(), 'server', '.wxeap'));
        memo.plugin('compression').use(compression_webpack_plugin_1.default, [
            {
                test: /\.js$|\.css$/,
                deleteOriginalAssets: true,
            },
        ]);
        return memo;
    },
    analyze: {
        analyzerMode: 'server',
        analyzerPort: 8888,
        openAnalyzer: false,
        generateStatsFile: false,
        statsFilename: 'stats.json',
        logLevel: 'info',
        defaultSizes: 'parsed',
    },
    extraBabelPlugins: [
        [
            'babel-plugin-import',
            {
                libraryName: '@material-ui/icons',
                // Use "'libraryDirectory': ''," if your bundler does not support ES modules
                libraryDirectory: 'esm',
                camel2DashComponentName: false,
            },
            'core',
        ],
    ],
}, extraOptions);
