webpack.config.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* eslint-disable */
  2. const HtmlWebpackPlugin = require("html-webpack-plugin");
  3. const ESLintPlugin = require("eslint-webpack-plugin");
  4. const CopyPlugin = require("copy-webpack-plugin");
  5. const webpack = require("webpack");
  6. const path = require("path");
  7. const appDirectory = path.resolve(__dirname, "./");
  8. const srcDirectory = path.resolve(__dirname, "../src");
  9. const rootDirectory = path.resolve(__dirname, "../../");
  10. const babelLoaderConfiguration = {
  11. test: /\.(tsx|ts|js|jsx)$/,
  12. include: [
  13. path.resolve(appDirectory, "index.tsx"),
  14. path.resolve(srcDirectory, "index.tsx"),
  15. path.resolve(srcDirectory),
  16. path.resolve(rootDirectory, "src"),
  17. path.resolve(rootDirectory, "node_modules/@react-navigation/native-stack"),
  18. path.resolve(rootDirectory, "node_modules/@react-native/new-app-screen"),
  19. path.resolve(rootDirectory, "node_modules/@react-navigation/elements"),
  20. path.resolve(rootDirectory, "node_modules/@react-navigation/native"),
  21. path.resolve(rootDirectory, "node_modules/react-native-uncompiled"),
  22. path.resolve(rootDirectory, "node_modules/lucide-react-native"),
  23. path.resolve(rootDirectory, "node_modules/react-native"),
  24. path.resolve(rootDirectory, "node_modules/expo-font"),
  25. path.resolve(rootDirectory, "node_modules/expo-modules-core"),
  26. path.resolve(rootDirectory, "node_modules/expo-asset")
  27. ],
  28. use: {
  29. loader: "babel-loader",
  30. options: {
  31. cacheDirectory: true,
  32. presets: [
  33. "module:@react-native/babel-preset",
  34. "@babel/preset-typescript"
  35. ],
  36. plugins: [
  37. "react-native-web"
  38. ]
  39. }
  40. }
  41. };
  42. const imageLoaderConfiguration = {
  43. test: /\.(gif|jpe?g|png|svg)$/,
  44. use: {
  45. loader: "url-loader",
  46. options: {
  47. name: "[name].[ext]",
  48. esModule: false
  49. }
  50. }
  51. };
  52. module.exports = {
  53. entry: [
  54. path.resolve(appDirectory, "index.tsx")
  55. ],
  56. mode: "development",
  57. devtool: "source-map",
  58. output: {
  59. path: path.resolve(appDirectory, "dist"),
  60. filename: "bundle.web.js",
  61. publicPath: "/"
  62. },
  63. devServer: {
  64. port: 3000,
  65. historyApiFallback: true,
  66. client: {
  67. logging: "none",
  68. overlay: {
  69. errors: true,
  70. warnings: false
  71. }
  72. }
  73. },
  74. ignoreWarnings: [
  75. {
  76. module: /lucide-react-native/
  77. },
  78. {
  79. module: /@react-navigation/
  80. },
  81. {
  82. module: /ncore-ui-kit/
  83. }
  84. ],
  85. module: {
  86. rules: [
  87. babelLoaderConfiguration,
  88. imageLoaderConfiguration,
  89. {
  90. test: /\.(js|mjs|jsx)$/,
  91. include: [
  92. path.resolve(rootDirectory, "node_modules/@react-navigation")
  93. ],
  94. type: "javascript/auto",
  95. resolve: {
  96. fullySpecified: false
  97. }
  98. },
  99. {
  100. test: /\.mjs$/,
  101. include: /node_modules/,
  102. type: "javascript/auto"
  103. },
  104. {
  105. test: /\.(ttf|otf|eot|woff|woff2)$/,
  106. type: "asset/resource",
  107. generator: {
  108. filename: "../src/assets/fonts/[name][ext]"
  109. }
  110. }
  111. ]
  112. },
  113. plugins: [
  114. new webpack.ProvidePlugin({
  115. process: "process/browser",
  116. Buffer: ["buffer", "Buffer"],
  117. }),
  118. new HtmlWebpackPlugin({
  119. template: path.resolve(appDirectory, "./public/index.html"),
  120. filename: "index.html"
  121. }),
  122. new webpack.DefinePlugin({
  123. "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development"),
  124. __DEV__: JSON.stringify(process.env.NODE_ENV !== "production"),
  125. "__REACT_DEVTOOLS_GLOBAL_HOOK__": "({ isDisabled: true })",
  126. "process.env.EXPO_OS": JSON.stringify("web"),
  127. "process.env": JSON.stringify({})
  128. }),
  129. new ESLintPlugin({
  130. overrideConfigFile: path.resolve(rootDirectory, "eslint.config.mjs"),
  131. failOnError: process.env.NODE_ENV === "production",
  132. exclude: [
  133. path.resolve(rootDirectory, "node_modules"),
  134. path.resolve(appDirectory, "dist")
  135. ],
  136. eslintPath: "eslint/use-at-your-own-risk",
  137. configType: "flat",
  138. emitWarning: true,
  139. extensions: [
  140. "tsx",
  141. "jsx",
  142. "ts",
  143. "js"
  144. ]
  145. }),
  146. new CopyPlugin({
  147. patterns: [
  148. {
  149. globOptions: {
  150. dot: true,
  151. ignore: [
  152. "**/index.html"
  153. ]
  154. },
  155. noErrorOnMissing: true,
  156. from: "public",
  157. to: "."
  158. }
  159. ]
  160. })
  161. ],
  162. resolve: {
  163. fallback: {
  164. "crypto": require.resolve("crypto-browserify"),
  165. "stream": require.resolve("stream-browserify"),
  166. "process": require.resolve("process/browser"),
  167. "vm": require.resolve("vm-browserify"),
  168. "buffer": require.resolve("buffer/"),
  169. "util": require.resolve("util/")
  170. },
  171. symlinks: false,
  172. alias: {
  173. "react-native$": "react-native-web",
  174. "ncore-ui-kit": path.resolve(rootDirectory, "src/index")
  175. },
  176. extensions: [
  177. ".web.tsx",
  178. ".web.ts",
  179. ".web.js",
  180. ".tsx",
  181. ".ts",
  182. ".js",
  183. ".mjs"
  184. ],
  185. modules: [
  186. path.resolve(rootDirectory, "node_modules"),
  187. "node_modules"
  188. ]
  189. }
  190. };