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

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
@@ -38,36 +38,25 @@ const extensions = [
38
38
  '.tsx',
39
39
  '.json',
40
40
  ];
41
- const nativeLegacyScriptPathPattern = /\.(js|flow)$/;
41
+ const reactNativeFlowJsxPathPattern = /\.(js|flow)$/;
42
+ const reactNativeFlowJsxLoader = 'jsx';
42
43
  const flowPragmaPattern = /@flow\b/;
43
44
  const useClientPragmaPattern = /['"]use client['"]/;
44
45
  const jsxElementPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>/;
45
46
  const jsxSelfClosingPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*\/?>/;
46
47
  const jsxFragmentPattern = /<>([\s\S]*?)<\/>/;
47
- const loaders = {
48
- '.js': 'jsx',
49
- '.flow': 'jsx',
50
- };
51
- const getLoader = (path) => {
52
- const ext = `.${path.split('.').pop()}`;
53
- if (ext in loaders) {
54
- return loaders[ext];
55
- }
56
- return 'default';
57
- };
58
48
  const esbuildPlugin = () => ({
59
49
  name: 'react-native-web',
60
50
  setup: (build) => {
61
- build.onLoad({ filter: nativeLegacyScriptPathPattern }, async (args) => {
51
+ build.onLoad({ filter: reactNativeFlowJsxPathPattern }, async (args) => {
62
52
  let contents = await fs.readFile(args.path, 'utf-8');
63
- if (nativeLegacyScriptPathPattern.test(args.path) && flowPragmaPattern.test(contents)) {
53
+ if (flowPragmaPattern.test(contents)) {
64
54
  const transformed = flowRemoveTypes(contents);
65
55
  contents = transformed.toString();
66
56
  }
67
- const loader = getLoader(args.path);
68
57
  return {
69
58
  contents,
70
- loader,
59
+ loader: reactNativeFlowJsxLoader,
71
60
  };
72
61
  });
73
62
  },
@@ -94,7 +83,7 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
94
83
  }),
95
84
  async transform(code, id) {
96
85
  id = id.split('?')[0];
97
- if (!nativeLegacyScriptPathPattern.test(id)) {
86
+ if (!reactNativeFlowJsxPathPattern.test(id)) {
98
87
  return;
99
88
  }
100
89
  let map = null;
@@ -108,9 +97,8 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
108
97
  };
109
98
  }
110
99
  if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
111
- const loader = getLoader(id);
112
100
  const result = await vite.transformWithEsbuild(code, id, {
113
- loader,
101
+ loader: reactNativeFlowJsxLoader,
114
102
  tsconfigRaw: {
115
103
  compilerOptions: {
116
104
  jsx: 'react-jsx',
package/dist/es/index.js CHANGED
@@ -34,36 +34,25 @@ const extensions = [
34
34
  '.tsx',
35
35
  '.json',
36
36
  ];
37
- const nativeLegacyScriptPathPattern = /\.(js|flow)$/;
37
+ const reactNativeFlowJsxPathPattern = /\.(js|flow)$/;
38
+ const reactNativeFlowJsxLoader = 'jsx';
38
39
  const flowPragmaPattern = /@flow\b/;
39
40
  const useClientPragmaPattern = /['"]use client['"]/;
40
41
  const jsxElementPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>/;
41
42
  const jsxSelfClosingPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*\/?>/;
42
43
  const jsxFragmentPattern = /<>([\s\S]*?)<\/>/;
43
- const loaders = {
44
- '.js': 'jsx',
45
- '.flow': 'jsx',
46
- };
47
- const getLoader = (path) => {
48
- const ext = `.${path.split('.').pop()}`;
49
- if (ext in loaders) {
50
- return loaders[ext];
51
- }
52
- return 'default';
53
- };
54
44
  const esbuildPlugin = () => ({
55
45
  name: 'react-native-web',
56
46
  setup: (build) => {
57
- build.onLoad({ filter: nativeLegacyScriptPathPattern }, async (args) => {
47
+ build.onLoad({ filter: reactNativeFlowJsxPathPattern }, async (args) => {
58
48
  let contents = await fs.readFile(args.path, 'utf-8');
59
- if (nativeLegacyScriptPathPattern.test(args.path) && flowPragmaPattern.test(contents)) {
49
+ if (flowPragmaPattern.test(contents)) {
60
50
  const transformed = flowRemoveTypes(contents);
61
51
  contents = transformed.toString();
62
52
  }
63
- const loader = getLoader(args.path);
64
53
  return {
65
54
  contents,
66
- loader,
55
+ loader: reactNativeFlowJsxLoader,
67
56
  };
68
57
  });
69
58
  },
@@ -90,7 +79,7 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
90
79
  }),
91
80
  async transform(code, id) {
92
81
  id = id.split('?')[0];
93
- if (!nativeLegacyScriptPathPattern.test(id)) {
82
+ if (!reactNativeFlowJsxPathPattern.test(id)) {
94
83
  return;
95
84
  }
96
85
  let map = null;
@@ -104,9 +93,8 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
104
93
  };
105
94
  }
106
95
  if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
107
- const loader = getLoader(id);
108
96
  const result = await transformWithEsbuild(code, id, {
109
- loader,
97
+ loader: reactNativeFlowJsxLoader,
110
98
  tsconfigRaw: {
111
99
  compilerOptions: {
112
100
  jsx: 'react-jsx',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-native-web",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },