const path = require("path")
const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const glob = require("glob")

module.exports = {
  watch: true,
  entry: './src/index.tsx',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'index.js',
    libraryTarget: 'commonjs2' // THIS IS THE MOST IMPORTANT LINE! :mindblow: I wasted more than 2 days until realize this was the line most important in all this guide.
  },
  // Enable sourcemaps for debugging webpack's output.
  devtool: "source-map",
  //mode:"development",
  resolve: {
      // Add '.ts' and '.tsx' as resolvable extensions.
      extensions: [".ts", ".tsx", ".js", ".json"]
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"],
      },
      // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
      { test: /\.tsx?$/, loader: "awesome-typescript-loader" },

      // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
      { test: /\.txt?$/, loader: "json-loader" },

      // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
      { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
    ]
    // loaders: [
    //     {
    //         test: /\.html$/,
    //         loader: 'file-loader?name=[name].[ext]',
    //     },
    //     {
    //         test: /\.jsx?$/,
    //         exclude: /node_modules/,
    //         loader: 'babel-loader',
    //         query: {
    //             presets: ['es2015', 'react']
    //         }
    //     },
    //     ,
    //     {
    //         test: /\.tsx?$/,
    //         exclude: /node_modules/,
    //         loader: 'babel-loader',
    //         query: {
    //             presets: ['es2015', 'react']
    //         }
    //     },
    // ]
  },
  //plugins: [new UglifyJsPlugin()],
  externals: {
    "react": "react",
    "react-dom": "react-dom",
    "process":"process",
    'react-pdf':'react-pdf',
    'office-ui-fabric-react/lib':'office-ui-fabric-react/lib',
    'office-ui-fabric-react':'office-ui-fabric-react',
  }
}