const path = require('path')

const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  mode: process.env.NODE_ENV,
  entry: './js/laraberg.js',
  output: {
    filename: 'laraberg.js',
    path: path.resolve(__dirname, '../js')
  },
  devtool: 'source-map',
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.(s*)css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader
          },
          'css-loader',
          'postcss-loader',
          'sass-loader'
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({ filename: '../css/laraberg.css' }),
    new CopyWebpackPlugin([
      { from: 'node_modules/tinymce/plugins', to: 'plugins' },
      { from: 'node_modules/tinymce/themes', to: 'themes' },
      { from: 'node_modules/tinymce/skins', to: 'skins' }
    ], {})
  ]
}