<commit_before>const path = require('path')
const webpack = require('webpack')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
const isProduction = process.argv.indexOf('-p') !== -1

module.exports = {
    context: __dirname,
    entry: {
        charts: "./js/charts.entry.ts",
        admin: "./js/admin.entry.ts",
        oldadmin: "./js/oldadmin.entry.ts"
    },
    output: {
        path: path.join(__dirname, "grapher_admin/static/build"),
        filename: (isProduction ? "[name].bundle.[chunkhash].js" : "[name].js")
    },
  	resolve: {
        extensions: [".ts", ".tsx", ".js", ".css"],
        alias: {
            'react': 'preact-compat',
            'react-dom': 'preact-compat',
        },
        modules: [
  	        path.join(__dirname, "js/libs"),
            path.join(__dirname, "css/libs"),
            path.join(__dirname, "node_modules"),
        ],
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: "ts-loader",
                options: {
                    transpileOnly: true,
                    configFile: path.join(__dirname, "tsconfig.client.json")
                }
            },
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader?modules&importLoaders=1&localIdentName=[local]', 'postcss-loader'] })
            },
            {
                test: /\.scss$/,
                loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader?modules&importLoaders=1&localIdentName=[local]', 'sass-loader'] })
            },
            {
                test: /\.(jpe?g|gif|png|eot|woff|ttf|svg|woff2)$/,
                loader: 'url-loader?limit=10000'
            }
        ],
    },

    // Enable sourcemaps for debugging webpack's output.
    devtool: (isProduction ? false : "cheap-module-eval-source-map"),

    plugins: (isProduction ? [
        // This plugin extracts css files required in the entry points
        // into a separate CSS bundle for download
        new ExtractTextPlugin('[name].bundle.[chunkhash].css'),

        // CSS optimization
        /*new OptimizeCssAssetsPlugin({
            assetNameRegExp: /\.bundle.*\.css$/,
            cssProcessorOptions: { discardComments: { removeAll: true } }
        }),*/

        // JS optimization
        new ParallelUglifyPlugin({
            cachePath: path.join(__dirname, 'tmp')
        }),

        // Output manifest so server can figure out the hashed
        // filenames
        new ManifestPlugin(),
    ] : [
        new ExtractTextPlugin('[name].css'),

        // Output manifest so server can figure out the hashed
        // filenames
        new ManifestPlugin(),
    ]),
    devServer: {
        host: 'localhost',
        port: 8090,
        contentBase: 'public',
        disableHostCheck: true,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
            "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
        }
    },
}<commit_msg>Use new webpack 'mode' feature<commit_after>const path = require('path')
const webpack = require('webpack')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')

module.exports = (env, argv) => {
    const isProduction = argv.mode === 'production'
    return {
        context: __dirname,
        entry: {
            charts: "./js/charts.entry.ts",
            admin: "./js/admin.entry.ts",
            oldadmin: "./js/oldadmin.entry.ts"
        },
        output: {
            path: path.join(__dirname, "grapher_admin/static/build"),
            filename: (isProduction ? "[name].bundle.[chunkhash].js" : "[name].js")
        },
          resolve: {
            extensions: [".ts", ".tsx", ".js", ".css"],
            alias: {
                'react': 'preact-compat',
                'react-dom': 'preact-compat',
            },
            modules: [
                path.join(__dirname, "css/libs"),
                path.join(__dirname, "node_modules"),
            ],
        },
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    loader: "ts-loader",
                    options: {
                        transpileOnly: true,
                        configFile: path.join(__dirname, "tsconfig.client.json")
                    }
                },
                {
                    test: /\.css$/,
                    loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader?modules&importLoaders=1&localIdentName=[local]', 'postcss-loader'] })
                },
                {
                    test: /\.scss$/,
                    loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader?modules&importLoaders=1&localIdentName=[local]', 'sass-loader'] })
                },
                {
                    test: /\.(jpe?g|gif|png|eot|woff|ttf|svg|woff2)$/,
                    loader: 'url-loader?limit=10000'
                }
            ],
        },
    
        plugins: (isProduction ? [
            // This plugin extracts css files required in the entry points
            // into a separate CSS bundle for download
            new ExtractTextPlugin('[name].bundle.[chunkhash].css'),
            // Output manifest so server can figure out the hashed filenames
            new ManifestPlugin(),
        ] : [
            new ExtractTextPlugin('[name].css'),    
            // Output manifest so server can figure out the hashed filenames
            new ManifestPlugin(),
        ]),
        devServer: {
            host: 'localhost',
            port: 8090,
            contentBase: 'public',
            disableHostCheck: true,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
                "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
            }
        },    
    }
}
{'fraction_non_alphanumeric': 0.14086005166388088, 'fraction_numerical': 0.003798814769791825, 'mean_word_length': 1.7265948632974317, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3780898', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1774, 'n_words': 354}