{"id":15019723,"url":"https://github.com/gabriel-logan/react-native-web-webpack-template","last_synced_at":"2026-01-04T14:33:10.248Z","repository":{"id":256581266,"uuid":"855827348","full_name":"gabriel-logan/react-native-web-webpack-template","owner":"gabriel-logan","description":"Basic starter template, showing how to correctly configure React Native Web using React Native Cli, using webpack and typescript.","archived":false,"fork":false,"pushed_at":"2024-09-20T19:29:59.000Z","size":2719,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T03:14:48.310Z","etag":null,"topics":["react","react-native","react-native-web","typescript","webpack"],"latest_commit_sha":null,"homepage":"https://gabriel-logan.github.io/react-native-web-webpack-template/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabriel-logan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"gabriellogan","custom":null}},"created_at":"2024-09-11T14:19:08.000Z","updated_at":"2024-09-20T19:30:02.000Z","dependencies_parsed_at":"2024-09-14T01:11:30.579Z","dependency_job_id":null,"html_url":"https://github.com/gabriel-logan/react-native-web-webpack-template","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":0.04166666666666663,"last_synced_commit":"a60241643b86913ed7fff971bc7b5ee28d4fead5"},"previous_names":["gabriel-logan/react-native-web-webpack-template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2Freact-native-web-webpack-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2Freact-native-web-webpack-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2Freact-native-web-webpack-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabriel-logan%2Freact-native-web-webpack-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabriel-logan","download_url":"https://codeload.github.com/gabriel-logan/react-native-web-webpack-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237999731,"owners_count":19399931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","react-native","react-native-web","typescript","webpack"],"created_at":"2024-09-24T19:53:56.574Z","updated_at":"2025-10-24T16:31:22.604Z","avatar_url":"https://github.com/gabriel-logan.png","language":"JavaScript","funding_links":["https://buymeacoffee.com/gabriellogan"],"categories":[],"sub_categories":[],"readme":"# React Native Cli - Webpack\n\n## Description\n\nBasic starter template, showing how to correctly configure React Native Web using React Native Cli, using webpack and typescript.\n\n## Installation\n\nFirst install React Native, if you already have it installed, skip this step.\n\n```sh\nnpx @react-native-community/cli@latest init web\n```\n\nRun\n\n```sh\ncd web/\n```\n\nNow install react native web and its dependencies\n\n```sh\nyarn add react-dom react-native-web\n```\n\nThe Babel plugin is recommended for build-time optimizations.\n\n```sh\nyarn add -D babel-plugin-react-native-web\n```\n\nInstall `webpack` dependencies\n\n```sh\nyarn add -D webpack webpack-cli webpack-dev-server html-webpack-plugin babel-loader babel-plugin-module-resolver url-loader @svgr/webpack\n```\n\n## Configuration files\n\nAdd the necessary scripts to run the project to your `package.json`\n\n```json\n\"build:web\": \"rm -rf dist/ \u0026\u0026 webpack --mode=production --config webpack.config.js --progress\",\n\"web\": \"webpack serve --mode=development --config webpack.config.js --progress\",\n```\n\n```json\n\"scripts\": {\n  \"android\": \"react-native run-android\",\n  \"ios\": \"react-native run-ios\",\n  \"build:web\": \"rm -rf dist/ \u0026\u0026 webpack --mode=production --config webpack.config.js --progress\", // This line for build project\n  \"web\": \"webpack serve --mode=development --config webpack.config.js --progress\", // This line for dev mode\n  \"lint\": \"eslint .\",\n  \"start\": \"react-native start\",\n  \"test\": \"jest\"\n},\n```\n\nCopy the code to `App.tsx`\n\nIf you want to have separate web files, create an App.web.tsx file and replace all the values ​​from the following steps.\n\n```js\nimport {\n  Linking,\n  StyleSheet,\n  Text,\n  TouchableOpacity,\n  View,\n} from \"react-native\";\n\nfunction App() {\n  return (\n    \u003cView style={styles.container}\u003e\n      \u003cText style={styles.title}\u003eHello World!\u003c/Text\u003e\n      \u003cText style={styles.subTitle}\u003eReact Native Web\u003c/Text\u003e\n      \u003cTouchableOpacity style={styles.button}\u003e\n        \u003cText style={styles.buttonText}\u003ePress Me\u003c/Text\u003e\n      \u003c/TouchableOpacity\u003e\n      \u003cText\u003e\n        Created by:{\" \"}\n        \u003cTouchableOpacity\n          onPress={() =\u003e {\n            Linking.openURL(\"https://github.com/gabriel-logan\");\n          }}\n        \u003e\n          \u003cText style={styles.link}\u003eGabriel Logan\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e{\" \"}\n        using{\" \"}\n        \u003cTouchableOpacity\n          onPress={() =\u003e {\n            Linking.openURL(\"https://necolas.github.io/react-native-web/\");\n          }}\n        \u003e\n          \u003cText style={styles.link}\u003eReact Native Web\u003c/Text\u003e\n        \u003c/TouchableOpacity\u003e\n        , Webpack and TypeScript\n      \u003c/Text\u003e\n    \u003c/View\u003e\n  );\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    flex: 1,\n    padding: 20,\n    alignItems: \"center\",\n  },\n  button: {\n    backgroundColor: \"#ADBDFF\",\n    padding: 10,\n    marginVertical: 20,\n    borderRadius: 5,\n  },\n  buttonText: {\n    fontSize: 20,\n  },\n  title: {\n    fontSize: 40,\n  },\n  subTitle: {\n    fontSize: 20,\n  },\n  paragraph: {\n    fontSize: 16,\n  },\n  link: {\n    color: \"blue\",\n    textDecorationLine: \"underline\",\n  },\n});\n\nexport default App;\n```\n\nCreate a file called `index.html` in the root folder of your project\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" /\u003e\n    \u003cmeta name=\"description\" content=\"React Native Web\" /\u003e\n    \u003ctitle\u003eReact Native Web\u003c/title\u003e\n    \u003cstyle\u003e\n      #app-root {\n        display: flex;\n        flex: 1 1 100%;\n        height: 100vh;\n      }\n    \u003c/style\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"app-root\"\u003e\u003c/div\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nNow create a file in the root folder named `index.web.js`\n\nPaste the code below\n\n```js\nimport { AppRegistry } from \"react-native\";\n\nimport App from \"./App\";\nimport { name as appName } from \"./app.json\";\nif (module.hot) {\n  module.hot.accept();\n}\nAppRegistry.registerComponent(appName, () =\u003e App);\nAppRegistry.runApplication(appName, {\n  initialProps: {},\n  rootTag: document.getElementById(\"app-root\"),\n});\n```\n\nNow create a webpack configuration file `webpack.config.js` in the root folder\n\nand paste the code below\n\n```js\nconst HtmlWebpackPlugin = require(\"html-webpack-plugin\");\nconst path = require(\"path\");\nconst webpack = require(\"webpack\");\n\nconst appDirectory = path.resolve(__dirname);\nconst { presets, plugins } = require(`${appDirectory}/babel.config.web.js`);\n\nconst compileNodeModules = [\n  // Add every react-native package that needs compiling\n  // 'react-native-gesture-handler',\n].map((moduleName) =\u003e path.resolve(appDirectory, `node_modules/${moduleName}`));\n\nconst babelLoaderConfiguration = {\n  test: /\\.js$|tsx?$/,\n  // Add every directory that needs to be compiled by Babel during the build.\n  include: [\n    path.resolve(__dirname, \"index.web.js\"), // Entry to your application\n    path.resolve(__dirname, \"App.tsx\"), // Change this to your main App file\n    path.resolve(__dirname, \"src\"),\n    ...compileNodeModules,\n  ],\n  use: {\n    loader: \"babel-loader\",\n    options: {\n      cacheDirectory: true,\n      presets,\n      plugins,\n    },\n  },\n};\n\nconst svgLoaderConfiguration = {\n  test: /\\.svg$/,\n  use: [\n    {\n      loader: \"@svgr/webpack\",\n    },\n  ],\n};\n\nconst imageLoaderConfiguration = {\n  test: /\\.(gif|jpe?g|png)$/,\n  use: {\n    loader: \"url-loader\",\n    options: {\n      name: \"[name].[ext]\",\n    },\n  },\n};\n\n/** @type {import(\"webpack\").Configuration} */\nmodule.exports = {\n  entry: {\n    app: path.join(__dirname, \"index.web.js\"),\n  },\n  output: {\n    path: path.resolve(appDirectory, \"dist\"),\n    publicPath: \"/\", // Using ./ for the github pages, change to / for local\n    filename: \"rnw.bundle.js\",\n  },\n  resolve: {\n    extensions: [\".web.tsx\", \".web.ts\", \".tsx\", \".ts\", \".web.js\", \".js\"],\n    alias: {\n      \"react-native$\": \"react-native-web\",\n    },\n  },\n  module: {\n    rules: [\n      babelLoaderConfiguration,\n      imageLoaderConfiguration,\n      svgLoaderConfiguration,\n    ],\n  },\n  plugins: [\n    new HtmlWebpackPlugin({\n      template: path.join(__dirname, \"index.html\"),\n    }),\n    new webpack.HotModuleReplacementPlugin(),\n    new webpack.DefinePlugin({\n      // See: https://github.com/necolas/react-native-web/issues/349\n      __DEV__: JSON.stringify(true),\n    }),\n  ],\n};\n```\n\nCreate a new babel file so there are no conflicts with the mobile version\n\nAdd settings to `babel.config.web.js`\n\n```js\nmodule.exports = {\n  presets: [\"module:@react-native/babel-preset\"],\n  plugins: [\n    [\n      \"module-resolver\",\n      {\n        alias: {\n          \"^react-native$\": \"react-native-web\",\n        },\n      },\n    ],\n    \"react-native-web\",\n  ],\n};\n```\n\nIf you need to create tests using `jest` add the configuration below to your test file\n\n```js\nmoduleNameMapper: {\n   \"^react-native$\": \"react-native-web\",\n},\n```\n\n## Additional\n\nTo copy public static files to production, add an additional configuration in `webpack`\n\n```sh\nyarn add -D copy-webpack-plugin\n```\n\nImport the configuration into your `webpack` configuration file\n\n```js\nconst CopyWebpackPlugin = require(\"copy-webpack-plugin\");\n```\n\nand finally add the configuration in the `plugin` part\n\n```js\nplugins: [\n  new HtmlWebpackPlugin({\n    template: path.join(__dirname, \"index.html\"),\n  }),\n  new webpack.HotModuleReplacementPlugin(),\n  new webpack.DefinePlugin({\n    // See: https://github.com/necolas/react-native-web/issues/349\n    __DEV__: JSON.stringify(true),\n  }),\n  new CopyWebpackPlugin({ // ADD THIS LINE\n    patterns: [{ from: \"public\", to: \"\" }],\n  }),\n],\n```\n\nWith these settings, all files inside the `public` folder will be compiled together to the `dist` folder.\n\nNow you can add a favicon for example in the `public/assets/favicon.png` folder\n\nAnd add it to your `index.html`\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\" /\u003e\n    \u003cmeta name=\"description\" content=\"React Native Web\" /\u003e\n    \u003clink rel=\"icon\" href=\"./assets/favicon.png\" /\u003e\n    \u003ctitle\u003eReact Native Web\u003c/title\u003e\n    \u003cstyle\u003e\n      #app-root {\n        display: flex;\n        flex: 1 1 100%;\n        height: 100vh;\n      }\n    \u003c/style\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"app-root\"\u003e\u003c/div\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nNow you will see your favicon appearing in development mode as well as in production.\n\n## Done\n\nYour react native web project configured with webpack is ready for the initial kickstart\n\nThanks for reading\n\nCreated by: Gabriel Logan using React Native Web\n\n## @react-navigation\n\nFollow the manual installation documentation for @react-navigation/native which is required to use React Navigation\n\nhttps://reactnavigation.org/docs/getting-started/\n\nThen use one of the Navigators you intend to use.\n\nFor example: Native Stack Navigator\n\nhttps://reactnavigation.org/docs/native-stack-navigator\n\nRead the information about web support\n\nhttps://reactnavigation.org/docs/web-support\n\nThe Example without React Navigation can be found in the docs folder\n\nIf you want to test with React Navigation, you can git clone the main repository.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabriel-logan%2Freact-native-web-webpack-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabriel-logan%2Freact-native-web-webpack-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabriel-logan%2Freact-native-web-webpack-template/lists"}