const env = require("dotenv")
const fs = require("fs")
const path = require("path")
const sharify = require("./sharify")

const webpack = require("webpack")
const webpackMerge = require("webpack-merge")
const { CheckerPlugin } = require("awesome-typescript-loader")

/**
 * Write out a file that stubs the data that’s normally shared with the client through the `sharify` module. This file
 * is then replaced in the product of webpack where normally the actual `sharify` module would be loaded.
 */
const { METAPHYSICS_ENDPOINT } = env.config().parsed
const sharifyPath = sharify({ METAPHYSICS_ENDPOINT })

/**
 * Only use HMR plugin in dev mode
 */
let plugins = [new CheckerPlugin()]
if (process.env.NODE_ENV === "development") {
  plugins.push(new webpack.HotModuleReplacementPlugin())
}

// A mix of  the base from Emission's webpack setup, and the simple config for
// storybooks: https://storybook.js.org/configurations/custom-webpack-config/

module.exports = {
  devtool: "#inline-source-map", // Otherwise getting errors about e.g. `Relay` not being defined.
  resolve: {
    extensions: [".js", ".jsx", ".ts", ".tsx"],
    alias: {
      sharify: sharifyPath.replace(/\.js$/, ""),
    },
  },
  module: {
    rules: [
      { test: /\.json$/, loader: "json-loader" },
      {
        exclude: [/node_modules/, /__tests__/],
        use: [
          {
            loader: "awesome-typescript-loader",
            options: {
              useBabel: true,
              useCache: true,
              useTranspileModule: true, // Supposedly faster, won’t work if/when we emit TS declaration files.
            },
          },
        ],
        test: /\.tsx?$/,
      },
    ],
  },
  plugins: plugins,
  node: {
    console: true,
    fs: "empty",
    net: "empty",
    tls: "empty",
  },
}

@@ -1707,93 +1707,6 @@
 ns,%0A
-  node: %7B%0A    console: true,%0A    fs: %22empty%22,%0A    net: %22empty%22,%0A    tls: %22empty%22,%0A  %7D,%0A
 %7D%0A

Remove unnecessary storybook webpack config