vite-plugin-react-native-web 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -9,21 +9,35 @@ var vite = require('vite');
9
9
  // import type { ViteReactNativeWebOptions } from '../types'
10
10
  const development = process.env.NODE_ENV === 'development';
11
11
  const extensions = [
12
+ // ⚠️ This currently does not work as expected (https://github.com/evanw/esbuild/issues/4053)
13
+ // '.web.mjs',
14
+ // '.mjs',
15
+ // '.web.js',
16
+ // '.js',
17
+ // '.web.mts',
18
+ // '.mts',
19
+ // '.web.ts',
20
+ // '.ts',
21
+ // '.web.jsx',
22
+ // '.jsx',
23
+ // '.web.tsx',
24
+ // '.tsx',
25
+ // '.json',
26
+ // ⚠️ Temporary fix
12
27
  '.web.mjs',
13
- '.mjs',
14
28
  '.web.js',
15
- '.js',
16
29
  '.web.mts',
17
- '.mts',
18
30
  '.web.ts',
19
- '.ts',
20
31
  '.web.jsx',
21
- '.jsx',
22
32
  '.web.tsx',
33
+ '.mjs',
34
+ '.js',
35
+ '.mts',
36
+ '.ts',
37
+ '.jsx',
23
38
  '.tsx',
24
39
  '.json',
25
40
  ];
26
- const scriptPathPattern = /\.(js|jsx|ts|tsx|flow)$/;
27
41
  const nativeLegacyScriptPathPattern = /\.(js|flow)$/;
28
42
  const flowPragmaPattern = /@flow\b/;
29
43
  const useClientPragmaPattern = /['"]use client['"]/;
@@ -44,21 +58,13 @@ const getLoader = (path) => {
44
58
  const esbuildPlugin = () => ({
45
59
  name: 'react-native-web',
46
60
  setup: (build) => {
47
- build.onLoad({ filter: scriptPathPattern }, async (args) => {
48
- let path = args.path;
49
- // We need to manually resolve .web files since the resolveExtensions option does not seem to work properly.
50
- const webPath = args.path.replace(/(\.[^/.]+)$/, '.web$1');
51
- try {
52
- await fs.access(webPath);
53
- path = webPath;
54
- }
55
- catch { }
56
- let contents = await fs.readFile(path, 'utf-8');
57
- const loader = getLoader(path);
58
- if (nativeLegacyScriptPathPattern.test(path) && flowPragmaPattern.test(contents)) {
61
+ build.onLoad({ filter: nativeLegacyScriptPathPattern }, async (args) => {
62
+ let contents = await fs.readFile(args.path, 'utf-8');
63
+ if (nativeLegacyScriptPathPattern.test(args.path) && flowPragmaPattern.test(contents)) {
59
64
  const transformed = flowRemoveTypes(contents);
60
65
  contents = transformed.toString();
61
66
  }
67
+ const loader = getLoader(args.path);
62
68
  return {
63
69
  contents,
64
70
  loader,
@@ -95,7 +101,11 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
95
101
  if (flowPragmaPattern.test(code)) {
96
102
  const transformed = flowRemoveTypes(code);
97
103
  code = transformed.toString();
98
- map = transformed.generateMap();
104
+ map = {
105
+ file: id,
106
+ toUrl: () => id,
107
+ ...transformed.generateMap(),
108
+ };
99
109
  }
100
110
  if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
101
111
  const loader = getLoader(id);
package/dist/es/index.js CHANGED
@@ -5,21 +5,35 @@ import { transformWithEsbuild } from 'vite';
5
5
  // import type { ViteReactNativeWebOptions } from '../types'
6
6
  const development = process.env.NODE_ENV === 'development';
7
7
  const extensions = [
8
+ // ⚠️ This currently does not work as expected (https://github.com/evanw/esbuild/issues/4053)
9
+ // '.web.mjs',
10
+ // '.mjs',
11
+ // '.web.js',
12
+ // '.js',
13
+ // '.web.mts',
14
+ // '.mts',
15
+ // '.web.ts',
16
+ // '.ts',
17
+ // '.web.jsx',
18
+ // '.jsx',
19
+ // '.web.tsx',
20
+ // '.tsx',
21
+ // '.json',
22
+ // ⚠️ Temporary fix
8
23
  '.web.mjs',
9
- '.mjs',
10
24
  '.web.js',
11
- '.js',
12
25
  '.web.mts',
13
- '.mts',
14
26
  '.web.ts',
15
- '.ts',
16
27
  '.web.jsx',
17
- '.jsx',
18
28
  '.web.tsx',
29
+ '.mjs',
30
+ '.js',
31
+ '.mts',
32
+ '.ts',
33
+ '.jsx',
19
34
  '.tsx',
20
35
  '.json',
21
36
  ];
22
- const scriptPathPattern = /\.(js|jsx|ts|tsx|flow)$/;
23
37
  const nativeLegacyScriptPathPattern = /\.(js|flow)$/;
24
38
  const flowPragmaPattern = /@flow\b/;
25
39
  const useClientPragmaPattern = /['"]use client['"]/;
@@ -40,21 +54,13 @@ const getLoader = (path) => {
40
54
  const esbuildPlugin = () => ({
41
55
  name: 'react-native-web',
42
56
  setup: (build) => {
43
- build.onLoad({ filter: scriptPathPattern }, async (args) => {
44
- let path = args.path;
45
- // We need to manually resolve .web files since the resolveExtensions option does not seem to work properly.
46
- const webPath = args.path.replace(/(\.[^/.]+)$/, '.web$1');
47
- try {
48
- await fs.access(webPath);
49
- path = webPath;
50
- }
51
- catch { }
52
- let contents = await fs.readFile(path, 'utf-8');
53
- const loader = getLoader(path);
54
- if (nativeLegacyScriptPathPattern.test(path) && flowPragmaPattern.test(contents)) {
57
+ build.onLoad({ filter: nativeLegacyScriptPathPattern }, async (args) => {
58
+ let contents = await fs.readFile(args.path, 'utf-8');
59
+ if (nativeLegacyScriptPathPattern.test(args.path) && flowPragmaPattern.test(contents)) {
55
60
  const transformed = flowRemoveTypes(contents);
56
61
  contents = transformed.toString();
57
62
  }
63
+ const loader = getLoader(args.path);
58
64
  return {
59
65
  contents,
60
66
  loader,
@@ -91,7 +97,11 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
91
97
  if (flowPragmaPattern.test(code)) {
92
98
  const transformed = flowRemoveTypes(code);
93
99
  code = transformed.toString();
94
- map = transformed.generateMap();
100
+ map = {
101
+ file: id,
102
+ toUrl: () => id,
103
+ ...transformed.generateMap(),
104
+ };
95
105
  }
96
106
  if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
97
107
  const loader = getLoader(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-native-web",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,16 +42,16 @@
42
42
  "react-native-web"
43
43
  ],
44
44
  "dependencies": {
45
- "flow-remove-types": "^2.233.0"
45
+ "flow-remove-types": "^2.259.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@biomejs/biome": "^1.9.4",
49
- "@rollup/plugin-typescript": "^11.1.6",
50
- "@types/node": "^20.12.4",
51
- "rollup": "^4.14.0",
52
- "tslib": "^2.6.2",
53
- "typescript": "^5.4.4",
54
- "vite": "^5.2.8"
49
+ "@rollup/plugin-typescript": "^12.1.2",
50
+ "@types/node": "^22.10.10",
51
+ "rollup": "^4.32.0",
52
+ "tslib": "^2.8.1",
53
+ "typescript": "^5.7.3",
54
+ "vite": "^6.0.11"
55
55
  },
56
56
  "types": "./types/index.d.ts"
57
57
  }