{"size": 3214, "ext": "js", "max_stars_repo_path": "config/webpack.dev.js", "max_stars_repo_name": "irohalab/Deneb", "max_stars_repo_stars_event_min_datetime": "2016-05-28T15:28:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T15:57:37.000Z", "max_issues_repo_path": "config/webpack.dev.js", "max_issues_repo_name": "irohalab/Deneb", "max_issues_repo_issues_event_min_datetime": "2016-05-24T09:00:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T10:12:26.000Z", "max_forks_repo_path": "config/webpack.dev.js", "max_forks_repo_name": "irohalab/Deneb", "max_forks_repo_forks_event_min_datetime": "2016-06-05T05:50:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-02T10:04:59.000Z"}
{"max_stars_count": 33, "max_issues_count": 61, "max_forks_count": 4, "avg_line_length": 31.2038834951, "max_line_length": 100, "alphanum_fraction": 0.5124455507}
const webpackMerge = require('webpack-merge');

const commonConfig = require('./webpack.common');
const helpers      = require('./helpers');
const chalk = require('chalk');
/**
 * Webpack Plugins
 */
const DefinePlugin = require('webpack/lib/DefinePlugin');
const { AngularCompilerPlugin } = require('@ngtools/webpack');

let PROXY_SETTINGS;
try {
    PROXY_SETTINGS = require('./dev.proxy');
} catch (e) {
    PROXY_SETTINGS = {
        '/api/*': {
            target: 'http://localhost:5000'
        },
        '/pic/*': {
            target: 'http://localhost:8000'
        },
        '/video/*': {
            target: 'http://localhost:8000'
        }
    };

    console.log(chalk.bold.yellow('cannot find config/dev.proxy.js use default proxy settings'));
}
console.log(chalk.cyan('proxy setting is'));
console.log('================================================');
Object.keys(PROXY_SETTINGS).forEach(function (urlPatten) {
    console.log(chalk.green(urlPatten) + '->' + chalk.bold.white(PROXY_SETTINGS[urlPatten].target));
});
console.log('================================================');

module.exports = function(metadata) {
    return webpackMerge(commonConfig(metadata), {
        mode: 'development',

        devtool: 'cheap-module-eval-source-map',

        output: {
            path: helpers.root('dist'),
            // publicPath: '/',
            filename: '[name].bundle.js',
            chunkFilename: '[name].chunk.js'
        },

        optimization: {
            noEmitOnErrors: true
        },

        module: {
            rules: [
                {
                    test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
                    use: '@ngtools/webpack',
                    exclude: [/src[\/\\]service-worker[\/\\]/]
                }
            ]
        },
        plugins: [
            new DefinePlugin({
                'ENV': JSON.stringify(metadata.ENV),
                'HMR': metadata.HMR,
                'SITE_TITLE': JSON.stringify(metadata.title),
                'CHROME_EXTENSION_ID': JSON.stringify(metadata.chrome_extension_id),
                'FIREFOX_EXTENSION_ID': JSON.stringify(metadata.firefox_extension_id),
                'EDGE_EXTENSION_ID': JSON.stringify(metadata.edge_extension_id),
                'FIREFOX_EXTENSION_URL': JSON.stringify(metadata.firefox_extension_url)
            }),
            new AngularCompilerPlugin({
                tsConfigPath: helpers.root('tsconfig.json'),
                entryModule: helpers.root('src/app/app.module#AppModule'),
                sourceMap: true,
                skipCodeGeneration: false,
                discoverLazyRoutes: true
            })
        ],
        devServer: {
            port: metadata.port,
            host: metadata.host,
            historyApiFallback: true,
            watchOptions: {
                aggregateTimeout: 300,
                poll: 1000
            },
            proxy: PROXY_SETTINGS,
            disableHostCheck: true
        },

        node: {
            global: true,
            crypto: 'empty',
            process: true,
            module: false,
            clearImmediate: false,
            setImmediate: false
        }
    });
};
