webpack.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const path = require("path");
  2. const HtmlWebpackPlugin = require("html-webpack-plugin");
  3. const webpack = require("webpack");
  4. const dotenv = require("dotenv");
  5. module.exports = () => {
  6. const env = dotenv.config().parsed;
  7. const envKeys = Object.keys(env).reduce((prev, next) => {
  8. prev[`process.env.${next}`] = JSON.stringify(env[next]);
  9. return prev;
  10. }, {});
  11. return {
  12. entry: "./src/index.tsx",
  13. target: "web",
  14. mode: "development",
  15. module: {
  16. rules: [
  17. {
  18. test: /\.(ts|tsx)$/,
  19. loader: "ts-loader",
  20. },
  21. {
  22. enforce: "pre",
  23. test: /\.js$/,
  24. loader: "source-map-loader",
  25. },
  26. {
  27. test: /\.(png|svg|jpg|gif|mp3)$/,
  28. use: ["file-loader"],
  29. },
  30. { test: /\.css$/, use: ["css-loader"] },
  31. {
  32. test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
  33. use: [
  34. {
  35. loader: "file-loader",
  36. options: {
  37. name: "[name].[ext]",
  38. outputPath: "fonts/",
  39. },
  40. },
  41. ],
  42. },
  43. ],
  44. },
  45. resolve: {
  46. modules: [path.resolve(__dirname, "src"), "node_modules"],
  47. extensions: ["*", ".tsx", ".ts", ".js", ".jsx", ".json"],
  48. },
  49. output: {
  50. filename: "bundle.js",
  51. path: path.resolve(__dirname, "build"),
  52. publicPath: "/",
  53. },
  54. devServer: {
  55. historyApiFallback: true,
  56. disableHostCheck: true,
  57. },
  58. plugins: [
  59. new HtmlWebpackPlugin({
  60. template: path.resolve(__dirname, "src", "index.html"),
  61. segmentKey: `${process.env.SEGMENT_PUBLIC_KEY}`,
  62. }),
  63. new webpack.DefinePlugin(envKeys),
  64. ],
  65. };
  66. };