vite-plugin-react-native-web 2.7.0 → 2.7.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 +113 -0
- package/dist/es/index.js +108 -0
- package/dist/es/package.json +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('node:fs/promises');
|
|
6
|
+
var flowRemoveTypes = require('flow-remove-types');
|
|
7
|
+
var vite = require('vite');
|
|
8
|
+
|
|
9
|
+
const development = process.env.NODE_ENV === 'development';
|
|
10
|
+
const extensions = [
|
|
11
|
+
'.web.mjs',
|
|
12
|
+
'.mjs',
|
|
13
|
+
'.web.js',
|
|
14
|
+
'.js',
|
|
15
|
+
'.web.mts',
|
|
16
|
+
'.mts',
|
|
17
|
+
'.web.ts',
|
|
18
|
+
'.ts',
|
|
19
|
+
'.web.jsx',
|
|
20
|
+
'.jsx',
|
|
21
|
+
'.web.tsx',
|
|
22
|
+
'.tsx',
|
|
23
|
+
'.json',
|
|
24
|
+
];
|
|
25
|
+
const reactNativeFlowJsxPathPattern = /\.(js|flow)$/;
|
|
26
|
+
const reactNativeFlowJsxLoader = 'jsx';
|
|
27
|
+
const flowPragmaPattern = /@flow\b/;
|
|
28
|
+
const esbuildPlugin = () => ({
|
|
29
|
+
name: 'react-native-web',
|
|
30
|
+
setup: (build) => {
|
|
31
|
+
build.onLoad({ filter: reactNativeFlowJsxPathPattern }, async (args) => {
|
|
32
|
+
let contents = await fs.readFile(args.path, 'utf-8');
|
|
33
|
+
if (flowPragmaPattern.test(contents)) {
|
|
34
|
+
const transformed = flowRemoveTypes(contents);
|
|
35
|
+
contents = transformed.toString();
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
contents,
|
|
39
|
+
loader: reactNativeFlowJsxLoader,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const reactNativeWeb = (options) => ({
|
|
45
|
+
enforce: 'pre',
|
|
46
|
+
name: 'react-native-web',
|
|
47
|
+
config: () => ({
|
|
48
|
+
define: {
|
|
49
|
+
global: 'globalThis',
|
|
50
|
+
__DEV__: JSON.stringify(development),
|
|
51
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
52
|
+
'process.env.EXPO_OS': JSON.stringify('web'),
|
|
53
|
+
},
|
|
54
|
+
build: {
|
|
55
|
+
commonjsOptions: {
|
|
56
|
+
extensions,
|
|
57
|
+
transformMixedEsModules: true,
|
|
58
|
+
},
|
|
59
|
+
rollupOptions: (options === null || options === void 0 ? void 0 : options.enableExpoManualChunk)
|
|
60
|
+
? {
|
|
61
|
+
output: {
|
|
62
|
+
manualChunks(id) {
|
|
63
|
+
if (id.includes('expo-modules-core')) {
|
|
64
|
+
return 'expo-modules-core';
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
entryFileNames: (chunk) => {
|
|
68
|
+
if (chunk.name === 'expo-modules-core') {
|
|
69
|
+
return '0-expo-modules-core.js';
|
|
70
|
+
}
|
|
71
|
+
return '[name].js';
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
: undefined,
|
|
76
|
+
},
|
|
77
|
+
resolve: {
|
|
78
|
+
extensions,
|
|
79
|
+
alias: [{ find: 'react-native', replacement: 'react-native-web' }],
|
|
80
|
+
},
|
|
81
|
+
optimizeDeps: {
|
|
82
|
+
esbuildOptions: {
|
|
83
|
+
plugins: [esbuildPlugin()],
|
|
84
|
+
resolveExtensions: extensions,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
async transform(code, id) {
|
|
89
|
+
id = id.split('?')[0];
|
|
90
|
+
if (!reactNativeFlowJsxPathPattern.test(id)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let map = null;
|
|
94
|
+
const transformed = flowRemoveTypes(code);
|
|
95
|
+
code = transformed.toString();
|
|
96
|
+
map = {
|
|
97
|
+
file: id,
|
|
98
|
+
toUrl: () => id,
|
|
99
|
+
...transformed.generateMap(),
|
|
100
|
+
};
|
|
101
|
+
const result = await vite.transformWithEsbuild(code, id, {
|
|
102
|
+
loader: reactNativeFlowJsxLoader,
|
|
103
|
+
jsx: 'automatic',
|
|
104
|
+
});
|
|
105
|
+
code = result.code;
|
|
106
|
+
map = result.map;
|
|
107
|
+
return { code, map };
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
exports.default = reactNativeWeb;
|
|
112
|
+
module.exports = Object.assign(exports.default, exports);
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import flowRemoveTypes from 'flow-remove-types';
|
|
3
|
+
import { transformWithEsbuild } from 'vite';
|
|
4
|
+
|
|
5
|
+
const development = process.env.NODE_ENV === 'development';
|
|
6
|
+
const extensions = [
|
|
7
|
+
'.web.mjs',
|
|
8
|
+
'.mjs',
|
|
9
|
+
'.web.js',
|
|
10
|
+
'.js',
|
|
11
|
+
'.web.mts',
|
|
12
|
+
'.mts',
|
|
13
|
+
'.web.ts',
|
|
14
|
+
'.ts',
|
|
15
|
+
'.web.jsx',
|
|
16
|
+
'.jsx',
|
|
17
|
+
'.web.tsx',
|
|
18
|
+
'.tsx',
|
|
19
|
+
'.json',
|
|
20
|
+
];
|
|
21
|
+
const reactNativeFlowJsxPathPattern = /\.(js|flow)$/;
|
|
22
|
+
const reactNativeFlowJsxLoader = 'jsx';
|
|
23
|
+
const flowPragmaPattern = /@flow\b/;
|
|
24
|
+
const esbuildPlugin = () => ({
|
|
25
|
+
name: 'react-native-web',
|
|
26
|
+
setup: (build) => {
|
|
27
|
+
build.onLoad({ filter: reactNativeFlowJsxPathPattern }, async (args) => {
|
|
28
|
+
let contents = await fs.readFile(args.path, 'utf-8');
|
|
29
|
+
if (flowPragmaPattern.test(contents)) {
|
|
30
|
+
const transformed = flowRemoveTypes(contents);
|
|
31
|
+
contents = transformed.toString();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
contents,
|
|
35
|
+
loader: reactNativeFlowJsxLoader,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const reactNativeWeb = (options) => ({
|
|
41
|
+
enforce: 'pre',
|
|
42
|
+
name: 'react-native-web',
|
|
43
|
+
config: () => ({
|
|
44
|
+
define: {
|
|
45
|
+
global: 'globalThis',
|
|
46
|
+
__DEV__: JSON.stringify(development),
|
|
47
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
48
|
+
'process.env.EXPO_OS': JSON.stringify('web'),
|
|
49
|
+
},
|
|
50
|
+
build: {
|
|
51
|
+
commonjsOptions: {
|
|
52
|
+
extensions,
|
|
53
|
+
transformMixedEsModules: true,
|
|
54
|
+
},
|
|
55
|
+
rollupOptions: (options === null || options === void 0 ? void 0 : options.enableExpoManualChunk)
|
|
56
|
+
? {
|
|
57
|
+
output: {
|
|
58
|
+
manualChunks(id) {
|
|
59
|
+
if (id.includes('expo-modules-core')) {
|
|
60
|
+
return 'expo-modules-core';
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
entryFileNames: (chunk) => {
|
|
64
|
+
if (chunk.name === 'expo-modules-core') {
|
|
65
|
+
return '0-expo-modules-core.js';
|
|
66
|
+
}
|
|
67
|
+
return '[name].js';
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
: undefined,
|
|
72
|
+
},
|
|
73
|
+
resolve: {
|
|
74
|
+
extensions,
|
|
75
|
+
alias: [{ find: 'react-native', replacement: 'react-native-web' }],
|
|
76
|
+
},
|
|
77
|
+
optimizeDeps: {
|
|
78
|
+
esbuildOptions: {
|
|
79
|
+
plugins: [esbuildPlugin()],
|
|
80
|
+
resolveExtensions: extensions,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
async transform(code, id) {
|
|
85
|
+
id = id.split('?')[0];
|
|
86
|
+
if (!reactNativeFlowJsxPathPattern.test(id)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let map = null;
|
|
90
|
+
const transformed = flowRemoveTypes(code);
|
|
91
|
+
code = transformed.toString();
|
|
92
|
+
map = {
|
|
93
|
+
file: id,
|
|
94
|
+
toUrl: () => id,
|
|
95
|
+
...transformed.generateMap(),
|
|
96
|
+
};
|
|
97
|
+
const result = await transformWithEsbuild(code, id, {
|
|
98
|
+
loader: reactNativeFlowJsxLoader,
|
|
99
|
+
jsx: 'automatic',
|
|
100
|
+
});
|
|
101
|
+
code = result.code;
|
|
102
|
+
map = result.map;
|
|
103
|
+
return { code, map };
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export { reactNativeWeb as default };
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|