Skip to content

Commit

Permalink
chore(example/basic): add windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMoch committed Feb 2, 2024
1 parent 0f9d241 commit cee47a8
Show file tree
Hide file tree
Showing 37 changed files with 1,959 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
49 changes: 33 additions & 16 deletions examples/basic/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const fs = require('fs');
const path = require('path');
const escape = require('escape-string-regexp');
const {getDefaultConfig} = require('@react-native/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const pak = require('../../package.json');

const rnwPath = fs.realpathSync(
path.resolve(require.resolve('react-native-windows/package.json'), '..'),
);

const pak = require('../../package.json');
const root = path.resolve(__dirname, '../..');
const modules = Object.keys({...pak.peerDependencies});

const defaultConfig = getDefaultConfig(__dirname);

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
...defaultConfig,

const config = {
projectRoot: __dirname,
watchFolders: [root],

// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
resolver: {
...defaultConfig.resolver,

blacklistRE: exclusionList(
modules.map(
m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`),
blockList: exclusionList([
// This stops "react-native run-windows" from causing the metro server to crash if its already running
new RegExp(
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
),
// This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip or other files produced by msbuild
new RegExp(`${rnwPath}/build/.*`),
new RegExp(`${rnwPath}/target/.*`),
/.*\.ProjectImports\.zip/,
]),
// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
blacklistRE: modules.map(
m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`),
),

extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
// This fixes the 'missing-asset-registry-path` error (see https://github.com/microsoft/react-native-windows/issues/11437)
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
},
};

module.exports = config;
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
9 changes: 6 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"windows": "react-native run-windows",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@react-native-picker/picker": "react-native-picker/picker",
"@react-native-picker/picker": "2.6.1",
"react": "18.2.0",
"react-native": "0.73.3"
"react-native": "0.73.3",
"react-native-windows": "0.73.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand All @@ -27,7 +29,8 @@
"eslint": "^8.19.0",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
"typescript": "5.0.4",
"metro-config": "^0.80.5"
},
"engines": {
"node": ">=18"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"react": ["./node_modules/@types/react"]
}
},
"include": ["./src/**/*", "**/*.js"],
"include": ["./src/**/*", "**/*.js", "metro.config.js"],
"exclude": ["node_modules"]
}
92 changes: 92 additions & 0 deletions examples/basic/windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
*AppPackages*
*BundleArtifacts*

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

#MonoDevelop
*.pidb
*.userprefs

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
*.sass-cache

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

# vim Temp Files
*~

#NuGet
packages/
*.nupkg

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl

#Test files
*.testsettings

#Other files
*.DotSettings
.vs/
*project.lock.json

#Files generated by the VS build
**/Generated Files/**

40 changes: 40 additions & 0 deletions examples/basic/windows/ExperimentalFeatures.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
This file contains some important settings that will apply globally for
your app and *all* native modules your app consumes. These values were
set when you created the app project, and in some cases cannot be
simply changed here without recreating a new project.
-->

<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
<!--
Enables default usage of Hermes.
See https://microsoft.github.io/react-native-windows/docs/hermes
-->
<UseHermes>true</UseHermes>

<!--
Changes compilation to assume use of WinUI 3 instead of System XAML.
Requires creation of new project.
See https://microsoft.github.io/react-native-windows/docs/winui3
-->
<UseWinUI3>false</UseWinUI3>

<!--
Changes compilation to assume use of Microsoft.ReactNative NuGet packages
instead of building the framework from source.
Requires creation of new project.
See https://microsoft.github.io/react-native-windows/docs/nuget
-->
<UseExperimentalNuget>false</UseExperimentalNuget>

<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>

</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions examples/basic/windows/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="packages" />
</config>
<packageSources>
<clear />
<add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
Loading

0 comments on commit cee47a8

Please sign in to comment.