const isEnvProduction = true;

const isEnvProductionProfile = true;

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;


const TerserPlugin = require('terser-webpack-plugin');

const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');


/*** webpack.config.js ***/


const path = require('path');

module.exports = {

    plugins: [
        new BundleAnalyzerPlugin()
    ],
 
    // mode: "production",
    // target: "node",


    entry: path.join(__dirname, "index.js"),
    output: {
        path: path.join(__dirname, "/build"),
        filename: "bootstrap-core-[name].bundle.js",
        // library: {
        //     type: 'umd',
        //     name: 'soxo-bootstrap-core'
        // },
        // path: path.join(__dirname, "/build"),
        // filename: "bootstrap-core.bundle.js"
    },
    module: {
        rules: [

            {
                test: /\.js$|jsx/,
                // test: /\.js$/,
                use: "babel-loader",
                exclude: /node_modules/
            },
            {
                test: /\.(s(a|c)ss)$/,
                // use: ['css-loader', 'sass-loader'],
                use: [
                    {
                        loader: 'style-loader',
                        options: {}
                        // options: { injectType: 'singletonStyleTag' }
                    },
                    "css-loader",
                    "sass-loader"
                ],

                exclude: /node_modules/

            },
            {
                test: /\.(css)$/,
                use: ['css-loader'],
                // exclude: /node_modules/
            },

            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },

            {
                test: /\.(png|jpe?g|gif)$/i,
                loader: 'url-loader',
                exclude: /node_modules/

            },


            // {
            //     test: /\.(png|jpe?g|gif)$/i,
            //     use: [
            //         {
            //             loader: 'file-loader',
            //         },
            //     ],
            //     // exclude: /node_modules/
            // },

        ]
    },

    // externals: {
    //     react: {
    //         commonjs: 'react',
    //         commonjs2: 'react',
    //         amd: 'react',
    //         root: '_',
    //     },
    //     antd: {
    //         root: 'antd',
    //         commonjs: 'antd',
    //         commonjs2: 'antd',
    //         amd: 'antd',
    //     }
    // },


    // optimization: {
    //     minimize: isEnvProduction,
    //     splitChunks: {
    //         chunks: 'all',
    //     },

    //     minimizer: [
    //         // This is only used in production mode
    //         new TerserPlugin({
    //             terserOptions: {
    //                 parse: {
    //                     // We want terser to parse ecma 8 code. However, we don't want it
    //                     // to apply any minification steps that turns valid ecma 5 code
    //                     // into invalid ecma 5 code. This is why the 'compress' and 'output'
    //                     // sections only apply transformations that are ecma 5 safe
    //                     // https://github.com/facebook/create-react-app/pull/4234
    //                     ecma: 8,
    //                 },
    //                 compress: {
    //                     ecma: 5,
    //                     warnings: false,
    //                     // Disabled because of an issue with Uglify breaking seemingly valid code:
    //                     // https://github.com/facebook/create-react-app/issues/2376
    //                     // Pending further investigation:
    //                     // https://github.com/mishoo/UglifyJS2/issues/2011
    //                     comparisons: false,
    //                     // Disabled because of an issue with Terser breaking valid code:
    //                     // https://github.com/facebook/create-react-app/issues/5250
    //                     // Pending further investigation:
    //                     // https://github.com/terser-js/terser/issues/120
    //                     inline: 2,
    //                 },
    //                 mangle: {
    //                     safari10: true,
    //                 },
    //                 // Added for profiling in devtools
    //                 keep_classnames: isEnvProductionProfile,
    //                 keep_fnames: isEnvProductionProfile,
    //                 output: {
    //                     ecma: 5,
    //                     comments: false,
    //                     // Turned on because emoji and regex is not minified properly using default
    //                     // https://github.com/facebook/create-react-app/issues/2488
    //                     ascii_only: true,
    //                 },
    //             },
    //         }),
    //         // This is only used in production mode
    //         new CssMinimizerPlugin(),
    //     ],
    // },



    resolve: {
        extensions: [".js", ".tsx"],

    },
    devServer: {
        port: 5003
    }
};