const path = require('path');
const webpack = require('webpack');
const { readFileSync } = require('fs');
const babelSettings = JSON.parse(readFileSync('.babelrc'));
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = {
  entry: {
    core: './src/modules/core.js',
    editor: './src/modules/editor.js',
    control: './src/modules/control.js',
    controls: './src/modules/controls.js',
  },
  devtool: false,
  // devtool: "cheap-source-map",
  output: { filename: '[name].js', path: path.resolve(__dirname, 'lib/dev') },
  module: {
    rules: [
      { test: /\.coffee$/, loader: 'coffee-loader' },
      { test: /\.pug$/, loader: 'pug-loader' },
      {
        test: /\.(html|js)$/,
        exclude: /node_modules/,
        use: { loader: 'babel-loader', options: babelSettings },
      },
      {
        test: /\.html$/,
        exclude: /node_modules/,
        use: { loader: 'svelte-loader', options: { shared: true } },
      },
    ],
  },
  // plugins: [ new BundleAnalyzerPlugin() ],
  resolve: {
    alias: {
      Core: path.resolve(__dirname, 'src/core/'),
      Editor: path.resolve(__dirname, 'src/editor/'),
    },
    extensions: ['.js', '.coffee', '.pug'],
  },
};
