const DtsBundlePlugin = require('./webpack/dtsBundlePlugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const path = require('path');

module.exports = {
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].js',
        chunkFilename: '[name].js',
        library: ['Nonstop'],
        libraryTarget: 'var'
    },
    externals: [

    ],
    plugins: [
        new DtsBundlePlugin(),
        new MiniCssExtractPlugin({
            filename: '[name].css',
            chunkFilename: '[name].css'
        }),
        new webpack.DefinePlugin({
            'VERSION': JSON.stringify(require('./package.json').version)
        }),
    ],
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx'],
        alias: {
            '~': path.join(__dirname, 'node_modules')
        }
    },
    module: {
        rules: [{
            test: /\.tsx?$/,
            enforce: 'pre',
            loader: 'tslint-loader',
            exclude: /node_modules/,
            options: {
                emitErrors: true,
                failOnHint: true,
                typeCheck: true
            }
        },
        {
            test: /\.tsx?$/,
            loader: 'ts-loader',
            exclude: /node_modules/
        },
        {
            test: /\.jsx?$/,
            exclude: /(node_modules)/,
            loader: 'babel-loader',
            options: {
                presets: [
                    '@babel/env'
                ],
            }
        },
        {
            test: /\.html$/,
            loader: 'html-loader?exportAsEs6Default',
            exclude: /node_modules/
        },
        {
            test: /\.s?css$/,
            use: [
                MiniCssExtractPlugin.loader,
                {
                    loader: 'css-loader',
                    options: {
                        sourceMap: true
                    }
                },
                {
                    loader: 'sass-loader',
                    options: {
                        sourceMap: true
                    }
                }
            ]
        },
        {
            test: /\.(woff2?|ttf|otf|eot|svg|png|jpg)$/,
            use: [
                {
                    loader: 'url-loader',
                    options: {
                        limit: 1024000
                    }
                }
            ]
        }
        ]
    }
};