webpack.config.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. const path = require("path");
  2. const webpack = require("webpack");
  3. const HtmlWebpackPlugin = require("html-webpack-plugin");
  4. const appDirectory = path.resolve(__dirname, "./");
  5. const srcDirectory = path.resolve(__dirname, "../src");
  6. const rootDirectory = path.resolve(__dirname, "../../");
  7. const babelLoaderConfiguration = {
  8. test: /\.(tsx|ts|js|jsx)$/,
  9. include: [
  10. path.resolve(appDirectory, "index.ts"),
  11. path.resolve(srcDirectory, "index.tsx"),
  12. path.resolve(srcDirectory),
  13. path.resolve(rootDirectory, "src"),
  14. path.resolve(rootDirectory, "node_modules/@react-navigation/native-stack"),
  15. path.resolve(rootDirectory, "node_modules/@react-native/new-app-screen"),
  16. path.resolve(rootDirectory, "node_modules/@react-navigation/elements"),
  17. path.resolve(rootDirectory, "node_modules/@react-navigation/native"),
  18. path.resolve(rootDirectory, "node_modules/react-native-uncompiled"),
  19. path.resolve(rootDirectory, "node_modules/lucide-react-native"),
  20. path.resolve(rootDirectory, "node_modules/react-native"),
  21. path.resolve(rootDirectory, "node_modules/expo-font"),
  22. path.resolve(rootDirectory, "node_modules/expo-modules-core"),
  23. path.resolve(rootDirectory, "node_modules/expo-asset")
  24. ],
  25. use: {
  26. loader: "babel-loader",
  27. options: {
  28. cacheDirectory: true,
  29. presets: [
  30. "module:@react-native/babel-preset",
  31. "@babel/preset-typescript"
  32. ],
  33. plugins: [
  34. "react-native-web"
  35. ]
  36. }
  37. }
  38. };
  39. const imageLoaderConfiguration = {
  40. test: /\.(gif|jpe?g|png|svg)$/,
  41. use: {
  42. loader: "url-loader",
  43. options: {
  44. name: "[name].[ext]",
  45. esModule: false
  46. }
  47. }
  48. };
  49. module.exports = {
  50. entry: [
  51. path.resolve(appDirectory, "index.ts")
  52. ],
  53. mode: "development",
  54. devtool: "source-map",
  55. output: {
  56. path: path.resolve(appDirectory, "dist"),
  57. filename: "bundle.web.js",
  58. publicPath: "/"
  59. },
  60. devServer: {
  61. port: 3000,
  62. historyApiFallback: true,
  63. client: {
  64. overlay: {
  65. errors: true,
  66. warnings: false
  67. }
  68. }
  69. },
  70. ignoreWarnings: [
  71. {
  72. module: /lucide-react-native/
  73. },
  74. {
  75. module: /@react-navigation/
  76. },
  77. {
  78. module: /ncore-ui-kit/
  79. }
  80. ],
  81. module: {
  82. rules: [
  83. babelLoaderConfiguration,
  84. imageLoaderConfiguration,
  85. {
  86. test: /\.(js|mjs|jsx)$/,
  87. include: [
  88. path.resolve(rootDirectory, "node_modules/@react-navigation")
  89. ],
  90. type: "javascript/auto",
  91. resolve: {
  92. fullySpecified: false
  93. }
  94. },
  95. {
  96. test: /\.mjs$/,
  97. include: /node_modules/,
  98. type: "javascript/auto"
  99. },
  100. {
  101. test: /\.(ttf|otf|eot|woff|woff2)$/,
  102. type: "asset/resource",
  103. generator: {
  104. filename: "../src/assets/fonts/[name][ext]"
  105. }
  106. }
  107. ]
  108. },
  109. plugins: [
  110. new HtmlWebpackPlugin({
  111. template: path.resolve(appDirectory, "./public/index.html"),
  112. filename: "index.html"
  113. }),
  114. new webpack.DefinePlugin({
  115. __DEV__: JSON.stringify(process.env.NODE_ENV !== "production"),
  116. "process.env": JSON.stringify({}),
  117. "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development")
  118. })
  119. ],
  120. resolve: {
  121. symlinks: false,
  122. alias: {
  123. "react-native$": "react-native-web",
  124. "ncore-ui-kit": path.resolve(rootDirectory, "src/index")
  125. },
  126. extensions: [
  127. ".web.tsx",
  128. ".web.ts",
  129. ".web.js",
  130. ".tsx",
  131. ".ts",
  132. ".js",
  133. ".mjs"
  134. ],
  135. modules: [
  136. path.resolve(rootDirectory, "node_modules"),
  137. "node_modules"
  138. ]
  139. }
  140. };