vite-plugin-react-native-web 1.1.1 → 1.2.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 +14 -8
- package/dist/es/index.js +14 -8
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vite = require('vite');
|
|
6
6
|
var flowRemoveTypes = require('flow-remove-types');
|
|
7
|
-
var fs = require('fs/promises');
|
|
7
|
+
var fs = require('node:fs/promises');
|
|
8
8
|
|
|
9
9
|
// import type { ViteReactNativeWebOptions } from '../types'
|
|
10
10
|
const development = process.env.NODE_ENV === 'development';
|
|
@@ -29,7 +29,7 @@ const loader = {
|
|
|
29
29
|
const filter = /\.(js|flow)$/;
|
|
30
30
|
const esbuildPlugin = () => ({
|
|
31
31
|
name: 'react-native-web',
|
|
32
|
-
setup: build => {
|
|
32
|
+
setup: (build) => {
|
|
33
33
|
build.onLoad({ filter }, async ({ path }) => {
|
|
34
34
|
const src = await fs.readFile(path, 'utf-8');
|
|
35
35
|
return {
|
|
@@ -44,7 +44,7 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
44
44
|
name: 'react-native-web',
|
|
45
45
|
config: () => ({
|
|
46
46
|
define: {
|
|
47
|
-
global: '
|
|
47
|
+
global: 'self',
|
|
48
48
|
__DEV__: JSON.stringify(development),
|
|
49
49
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
50
50
|
},
|
|
@@ -59,18 +59,20 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
61
|
}),
|
|
62
|
-
transform(code, id) {
|
|
62
|
+
async transform(code, id) {
|
|
63
|
+
id = id.split('?')[0];
|
|
63
64
|
if (!filter.test(id)) {
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
let includeSourceMaps = true;
|
|
68
|
+
// Do not include source maps for files that are using 'use client' pragma since these break the esbuild mappings (https://github.com/vitejs/vite/issues/15012)
|
|
69
|
+
if (code.includes("'use client'") || code.includes('"use client"')) {
|
|
70
|
+
includeSourceMaps = false;
|
|
69
71
|
}
|
|
70
72
|
if (code.includes('@flow')) {
|
|
71
73
|
code = flowRemoveTypes(code).toString();
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
const result = await vite.transformWithEsbuild(code, id, {
|
|
74
76
|
loader: loader['.js'],
|
|
75
77
|
tsconfigRaw: {
|
|
76
78
|
compilerOptions: {
|
|
@@ -78,6 +80,10 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
78
80
|
},
|
|
79
81
|
},
|
|
80
82
|
});
|
|
83
|
+
return {
|
|
84
|
+
code: result.code,
|
|
85
|
+
map: includeSourceMaps ? result.map : null,
|
|
86
|
+
};
|
|
81
87
|
},
|
|
82
88
|
});
|
|
83
89
|
|
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { transformWithEsbuild } from 'vite';
|
|
2
2
|
import flowRemoveTypes from 'flow-remove-types';
|
|
3
|
-
import fs from 'fs/promises';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
4
|
|
|
5
5
|
// import type { ViteReactNativeWebOptions } from '../types'
|
|
6
6
|
const development = process.env.NODE_ENV === 'development';
|
|
@@ -25,7 +25,7 @@ const loader = {
|
|
|
25
25
|
const filter = /\.(js|flow)$/;
|
|
26
26
|
const esbuildPlugin = () => ({
|
|
27
27
|
name: 'react-native-web',
|
|
28
|
-
setup: build => {
|
|
28
|
+
setup: (build) => {
|
|
29
29
|
build.onLoad({ filter }, async ({ path }) => {
|
|
30
30
|
const src = await fs.readFile(path, 'utf-8');
|
|
31
31
|
return {
|
|
@@ -40,7 +40,7 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
40
40
|
name: 'react-native-web',
|
|
41
41
|
config: () => ({
|
|
42
42
|
define: {
|
|
43
|
-
global: '
|
|
43
|
+
global: 'self',
|
|
44
44
|
__DEV__: JSON.stringify(development),
|
|
45
45
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
46
46
|
},
|
|
@@ -55,18 +55,20 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
}),
|
|
58
|
-
transform(code, id) {
|
|
58
|
+
async transform(code, id) {
|
|
59
|
+
id = id.split('?')[0];
|
|
59
60
|
if (!filter.test(id)) {
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
let includeSourceMaps = true;
|
|
64
|
+
// Do not include source maps for files that are using 'use client' pragma since these break the esbuild mappings (https://github.com/vitejs/vite/issues/15012)
|
|
65
|
+
if (code.includes("'use client'") || code.includes('"use client"')) {
|
|
66
|
+
includeSourceMaps = false;
|
|
65
67
|
}
|
|
66
68
|
if (code.includes('@flow')) {
|
|
67
69
|
code = flowRemoveTypes(code).toString();
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
const result = await transformWithEsbuild(code, id, {
|
|
70
72
|
loader: loader['.js'],
|
|
71
73
|
tsconfigRaw: {
|
|
72
74
|
compilerOptions: {
|
|
@@ -74,6 +76,10 @@ const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
|
74
76
|
},
|
|
75
77
|
},
|
|
76
78
|
});
|
|
79
|
+
return {
|
|
80
|
+
code: result.code,
|
|
81
|
+
map: includeSourceMaps ? result.map : null,
|
|
82
|
+
};
|
|
77
83
|
},
|
|
78
84
|
});
|
|
79
85
|
|