const Encore = require('@symfony/webpack-encore');
const path = require('path');

const projectData = {
    default: {
        entryPoints: {
            app: 'js/app.js',
            login: 'js/components/login.js',
            register: 'js/components/register.js',
            dart: 'js/components/dart.js',
            playersHandler: 'js/components/playersHandler.js',
            game: 'js/components/game.js',
            home: 'js/components/home.js',
            socketClient: 'js/components/socketClient.js',
        }
    }
};

if (!Encore.isRuntimeEnvironmentConfigured()) {
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

Encore
    .setManifestKeyPrefix('/')

    .addStyleEntry('debug', './themes/default/styles/debug.pcss')

    .addAliases({'_root': path.resolve(__dirname, './')})

    .copyFiles({from: './themes/default/fonts', to: 'fonts/[path][name].[ext]'})
    .copyFiles({from: './themes/default/images', to: 'images/[path][name].[ext]'})

    .splitEntryChunks()
    .enableSingleRuntimeChunk()

    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    .enableVersioning(Encore.isProduction())

    .configureImageRule({}, function(rule) {
        rule.oneOf.unshift({
            test: /\.svg$/i,
            loader: 'svg-inline-loader'
        })
    })

    .enablePostCssLoader();

Encore
    .setOutputPath('../public/default/')
    .setPublicPath('/default');

for (const [name, path] of Object.entries(projectData.default.entryPoints)) {
    Encore.addEntry(name, './themes/default/' + path);
}

module.exports = Encore.getWebpackConfig();
