Skip to content

Commit 6b98299

Browse files
committed
chore(react-native): Fix RN not loading properly
1 parent 6ed1e83 commit 6b98299

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

.changeset/curvy-wolves-say.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@plextv/vite-plugin-react-native-lightning": patch
3+
"@plextv/react-lightning-plugin-flexbox": patch
4+
---
5+
6+
chore(react-native): Fix RN not loading properly

packages/configs/vite.config.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { defineConfig } from 'vite';
22

3+
const esmExt = 'js';
4+
const cjsExt = 'cjs';
35
const createEntryCode = (fileName) => `'use strict';
46
if (process.env.NODE_ENV === 'production') {
5-
module.exports = require('./${fileName}.production.min.js');
7+
module.exports = require('./${fileName}.production.${cjsExt}');
68
} else {
7-
module.exports = require('./${fileName}.development.js');
9+
module.exports = require('./${fileName}.development.${cjsExt}');
810
}`;
911

1012
/**
@@ -29,7 +31,7 @@ const generateEntryFile = {
2931

3032
this.emitFile({
3133
type: 'asset',
32-
fileName: `cjs/${name}.js`,
34+
fileName: `cjs/${name}.${cjsExt}`,
3335
source: createEntryCode(name),
3436
});
3537
},
@@ -41,7 +43,7 @@ export default defineConfig(({ mode }) => ({
4143
entry: 'src/index.ts',
4244
name: 'index',
4345
fileName: (format, entryName) =>
44-
`${format}/${entryName}.${mode}.${format === 'es' ? 'mjs' : 'js'}`,
46+
`${format}/${entryName}.${mode}.${format === 'es' ? esmExt : cjsExt}`,
4547
formats: ['es', 'cjs'],
4648
},
4749
minify: mode === 'production',

packages/plugin-flexbox/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/plexinc/react-lightning/issues/new"
1313
},
1414
"type": "module",
15-
"main": "./dist/cjs/index.js",
15+
"main": "./dist/cjs/index.cjs",
1616
"module": "./dist/es/index.production.js",
1717
"types": "./dist/types/index.d.ts",
1818
"exports": {
@@ -26,7 +26,7 @@
2626
"exports": {
2727
".": {
2828
"import": "./dist/es/index.production.js",
29-
"require": "./dist/cjs/index.js",
29+
"require": "./dist/cjs/index.cjs",
3030
"types": "./dist/types/index.d.ts"
3131
},
3232
"./package.json": "./package.json",

packages/vite-plugin-react-native-lightning/src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createRequire } from 'node:module';
21
import react from '@vitejs/plugin-react';
32
import type { PluginOption } from 'vite';
43

@@ -24,11 +23,6 @@ type Options = {
2423
};
2524

2625
const vitePlugin = (options?: Options): PluginOption => {
27-
const require = createRequire(options?.cwd ?? process.cwd());
28-
const reactNativeLightningPath = require.resolve(
29-
'@plextv/react-native-lightning',
30-
);
31-
3226
return [
3327
react(options?.reactOptions),
3428
{
@@ -43,7 +37,7 @@ const vitePlugin = (options?: Options): PluginOption => {
4337
resolve: {
4438
extensions,
4539
alias: {
46-
'react-native': reactNativeLightningPath,
40+
'react-native': '@plextv/react-native-lightning',
4741
},
4842
},
4943
}),

0 commit comments

Comments
 (0)