webpack.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.ts"),
  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.ts")
  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. overlay: {
  68. errors: true,
  69. warnings: false
  70. }
  71. }
  72. },
  73. ignoreWarnings: [
  74. {
  75. module: /lucide-react-native/
  76. },
  77. {
  78. module: /@react-navigation/
  79. },
  80. {
  81. module: /ncore-ui-kit/
  82. }
  83. ],
  84. module: {
  85. rules: [
  86. babelLoaderConfiguration,
  87. imageLoaderConfiguration,
  88. {
  89. test: /\.(js|mjs|jsx)$/,
  90. include: [
  91. path.resolve(rootDirectory, "node_modules/@react-navigation")
  92. ],
  93. type: "javascript/auto",
  94. resolve: {
  95. fullySpecified: false
  96. }
  97. },
  98. {
  99. test: /\.mjs$/,
  100. include: /node_modules/,
  101. type: "javascript/auto"
  102. },
  103. {
  104. test: /\.(ttf|otf|eot|woff|woff2)$/,
  105. type: "asset/resource",
  106. generator: {
  107. filename: "../src/assets/fonts/[name][ext]"
  108. }
  109. }
  110. ]
  111. },
  112. plugins: [
  113. new HtmlWebpackPlugin({
  114. template: path.resolve(appDirectory, "./public/index.html"),
  115. filename: "index.html"
  116. }),
  117. new webpack.DefinePlugin({
  118. "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development"),
  119. __DEV__: JSON.stringify(process.env.NODE_ENV !== "production"),
  120. "process.env": JSON.stringify({})
  121. }),
  122. new ESLintPlugin({
  123. overrideConfigFile: path.resolve(rootDirectory, "eslint.config.mjs"),
  124. failOnError: process.env.NODE_ENV === "production",
  125. exclude: [
  126. path.resolve(rootDirectory, "node_modules"),
  127. path.resolve(appDirectory, "dist")
  128. ],
  129. eslintPath: "eslint/use-at-your-own-risk",
  130. configType: "flat",
  131. emitWarning: true,
  132. extensions: [
  133. "tsx",
  134. "jsx",
  135. "ts",
  136. "js"
  137. ]
  138. }),
  139. new CopyPlugin({
  140. patterns: [
  141. {
  142. globOptions: {
  143. ignore: [
  144. "**/index.html"
  145. ]
  146. },
  147. noErrorOnMissing: true,
  148. from: "public",
  149. to: "."
  150. }
  151. ]
  152. })
  153. ],
  154. resolve: {
  155. symlinks: false,
  156. alias: {
  157. "react-native$": "react-native-web",
  158. "ncore-ui-kit": path.resolve(rootDirectory, "src/index")
  159. },
  160. extensions: [
  161. ".web.tsx",
  162. ".web.ts",
  163. ".web.js",
  164. ".tsx",
  165. ".ts",
  166. ".js",
  167. ".mjs"
  168. ],
  169. modules: [
  170. path.resolve(rootDirectory, "node_modules"),
  171. "node_modules"
  172. ]
  173. }
  174. };