const path = require('path');
const nodeExternals = require('webpack-node-externals');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const config = {
    entry: './src/index.ts',

    target: 'node',
    node: {
        __dirname: false
    },
    //devtool: 'inline-source-map',
    externals: [
        nodeExternals(),
        {
            ldapConfig: './ldap_config.json',
            credentialsConfig: './ldap_connexion_config.json'
        }
    ],
    
    module: {
        rules: [{
            test: /\.js$/,
            use: ['eslint-loader']
        },{
            test: /\.ts$/,
            use: ['ts-loader'],
        },{
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        },{
            type: 'javascript/auto',
            test: /\.json$/,
            use: ['file-loader']
        }, {
            test: /\.graphql?$/,
            use: [
                {
                    loader: 'webpack-graphql-loader',
                    options: {
                        // validate: true,
                        // schema: "./path/to/schema.json",
                        // removeUnusedFragments: true
                        // etc. See "Loader Options" below
                    }
                }
            ]
        },{
            test: /\.(png|jpg|ico)$/,
            loader: 'file-loader',
            options: {
                limit: 10000
            }
        }]
    },
    resolve: {
        extensions: ['.ts', '.js']
    },
    plugins: [
        new CopyWebpackPlugin([{
            from: 'src/css',
            to: 'css'
        },{
            from: 'src/views',
            to: 'views'
        }]
        )
    ],

    output: {
        path: path.resolve(__dirname, 'build'),
        publicPath: '/assets/',
        filename: 'bundle.js'
    },
};

module.exports = config;