vite-plugin-react-native-web 2.6.0 → 2.7.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/README.md +1 -1
- package/package.json +2 -2
- package/dist/cjs/index.js +0 -144
- package/dist/es/index.js +0 -139
- package/dist/es/package.json +0 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ export default defineConfig({
|
|
|
26
26
|
|
|
27
27
|
The plugin accepts an options object with the following optional properties:
|
|
28
28
|
|
|
29
|
-
- `enableExpoManualChunk` (boolean): When set to true, this option enables manual chunking for expo-modules-core modules to optimize bundle size and loading performance. Default is
|
|
29
|
+
- `enableExpoManualChunk` (boolean): When set to true, this option enables manual chunking for expo-modules-core modules to optimize bundle size and loading performance. Default is false. Be cautious when enabling this option, since it overrides user-defined manual chunks in the Vite configuration.
|
|
30
30
|
|
|
31
31
|
If you are getting errors please report them in the issues section.
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-native-web",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rollup -c",
|
|
27
|
-
"lint": "biome check --write ./src ./types ./biome.json ./tsconfig.json ./rollup.config.mjs",
|
|
27
|
+
"lint": "biome check --write ./src ./types ./biome.json ./tsconfig.json ./rollup.config.mjs ./example/tsconfig.app.json ./example/tsconfig.node.json ./example/tsconfig.json ./example/vite.config.ts ./example/src",
|
|
28
28
|
"prerelease": "npm run build",
|
|
29
29
|
"release": "npm publish"
|
|
30
30
|
},
|
package/dist/cjs/index.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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
|
-
// ⚠️ This currently does not work as expected (https://github.com/evanw/esbuild/issues/4053)
|
|
12
|
-
// '.web.mjs',
|
|
13
|
-
// '.mjs',
|
|
14
|
-
// '.web.js',
|
|
15
|
-
// '.js',
|
|
16
|
-
// '.web.mts',
|
|
17
|
-
// '.mts',
|
|
18
|
-
// '.web.ts',
|
|
19
|
-
// '.ts',
|
|
20
|
-
// '.web.jsx',
|
|
21
|
-
// '.jsx',
|
|
22
|
-
// '.web.tsx',
|
|
23
|
-
// '.tsx',
|
|
24
|
-
// '.json',
|
|
25
|
-
// ⚠️ Temporary fix
|
|
26
|
-
'.web.mjs',
|
|
27
|
-
'.web.js',
|
|
28
|
-
'.web.mts',
|
|
29
|
-
'.web.ts',
|
|
30
|
-
'.web.jsx',
|
|
31
|
-
'.web.tsx',
|
|
32
|
-
'.mjs',
|
|
33
|
-
'.js',
|
|
34
|
-
'.mts',
|
|
35
|
-
'.ts',
|
|
36
|
-
'.jsx',
|
|
37
|
-
'.tsx',
|
|
38
|
-
'.json',
|
|
39
|
-
];
|
|
40
|
-
const reactNativeFlowJsxPathPattern = /\.(js|flow)$/;
|
|
41
|
-
const reactNativeFlowJsxLoader = 'jsx';
|
|
42
|
-
const flowPragmaPattern = /@flow\b/;
|
|
43
|
-
const useClientPragmaPattern = /['"]use client['"]/;
|
|
44
|
-
const jsxElementPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>/;
|
|
45
|
-
const jsxSelfClosingPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*\/?>/;
|
|
46
|
-
const jsxFragmentPattern = /<>([\s\S]*?)<\/>/;
|
|
47
|
-
const esbuildPlugin = () => ({
|
|
48
|
-
name: 'react-native-web',
|
|
49
|
-
setup: (build) => {
|
|
50
|
-
build.onLoad({ filter: reactNativeFlowJsxPathPattern }, async (args) => {
|
|
51
|
-
let contents = await fs.readFile(args.path, 'utf-8');
|
|
52
|
-
if (flowPragmaPattern.test(contents)) {
|
|
53
|
-
const transformed = flowRemoveTypes(contents);
|
|
54
|
-
contents = transformed.toString();
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
contents,
|
|
58
|
-
loader: reactNativeFlowJsxLoader,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
const reactNativeWeb = (options) => ({
|
|
64
|
-
enforce: 'pre',
|
|
65
|
-
name: 'react-native-web',
|
|
66
|
-
config: () => ({
|
|
67
|
-
define: {
|
|
68
|
-
global: 'globalThis',
|
|
69
|
-
__DEV__: JSON.stringify(development),
|
|
70
|
-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
71
|
-
'process.env.EXPO_OS': JSON.stringify('web'),
|
|
72
|
-
},
|
|
73
|
-
build: {
|
|
74
|
-
commonjsOptions: {
|
|
75
|
-
extensions,
|
|
76
|
-
transformMixedEsModules: true,
|
|
77
|
-
},
|
|
78
|
-
rollupOptions: (options === null || options === void 0 ? void 0 : options.enableExpoManualChunk) !== false
|
|
79
|
-
? {
|
|
80
|
-
output: {
|
|
81
|
-
manualChunks(id) {
|
|
82
|
-
if (id.includes('expo-modules-core')) {
|
|
83
|
-
return 'expo-modules-core';
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
entryFileNames: (chunk) => {
|
|
87
|
-
if (chunk.name === 'expo-modules-core') {
|
|
88
|
-
return '0-expo-modules-core.js';
|
|
89
|
-
}
|
|
90
|
-
return '[name].js';
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
: undefined,
|
|
95
|
-
},
|
|
96
|
-
resolve: {
|
|
97
|
-
extensions,
|
|
98
|
-
alias: [{ find: 'react-native', replacement: 'react-native-web' }],
|
|
99
|
-
},
|
|
100
|
-
optimizeDeps: {
|
|
101
|
-
esbuildOptions: {
|
|
102
|
-
plugins: [esbuildPlugin()],
|
|
103
|
-
resolveExtensions: extensions,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
}),
|
|
107
|
-
async transform(code, id) {
|
|
108
|
-
id = id.split('?')[0];
|
|
109
|
-
if (!reactNativeFlowJsxPathPattern.test(id)) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
let map = null;
|
|
113
|
-
if (flowPragmaPattern.test(code)) {
|
|
114
|
-
const transformed = flowRemoveTypes(code);
|
|
115
|
-
code = transformed.toString();
|
|
116
|
-
map = {
|
|
117
|
-
file: id,
|
|
118
|
-
toUrl: () => id,
|
|
119
|
-
...transformed.generateMap(),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
|
|
123
|
-
const result = await vite.transformWithEsbuild(code, id, {
|
|
124
|
-
loader: reactNativeFlowJsxLoader,
|
|
125
|
-
tsconfigRaw: {
|
|
126
|
-
compilerOptions: {
|
|
127
|
-
jsx: 'react-jsx',
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
code = result.code;
|
|
132
|
-
map = result.map;
|
|
133
|
-
// 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)
|
|
134
|
-
if (useClientPragmaPattern.test(code)) {
|
|
135
|
-
map = null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return { code, map };
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
exports.default = reactNativeWeb;
|
|
143
|
-
module.exports = Object.assign(exports.default, exports);
|
|
144
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
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
|
-
// ⚠️ This currently does not work as expected (https://github.com/evanw/esbuild/issues/4053)
|
|
8
|
-
// '.web.mjs',
|
|
9
|
-
// '.mjs',
|
|
10
|
-
// '.web.js',
|
|
11
|
-
// '.js',
|
|
12
|
-
// '.web.mts',
|
|
13
|
-
// '.mts',
|
|
14
|
-
// '.web.ts',
|
|
15
|
-
// '.ts',
|
|
16
|
-
// '.web.jsx',
|
|
17
|
-
// '.jsx',
|
|
18
|
-
// '.web.tsx',
|
|
19
|
-
// '.tsx',
|
|
20
|
-
// '.json',
|
|
21
|
-
// ⚠️ Temporary fix
|
|
22
|
-
'.web.mjs',
|
|
23
|
-
'.web.js',
|
|
24
|
-
'.web.mts',
|
|
25
|
-
'.web.ts',
|
|
26
|
-
'.web.jsx',
|
|
27
|
-
'.web.tsx',
|
|
28
|
-
'.mjs',
|
|
29
|
-
'.js',
|
|
30
|
-
'.mts',
|
|
31
|
-
'.ts',
|
|
32
|
-
'.jsx',
|
|
33
|
-
'.tsx',
|
|
34
|
-
'.json',
|
|
35
|
-
];
|
|
36
|
-
const reactNativeFlowJsxPathPattern = /\.(js|flow)$/;
|
|
37
|
-
const reactNativeFlowJsxLoader = 'jsx';
|
|
38
|
-
const flowPragmaPattern = /@flow\b/;
|
|
39
|
-
const useClientPragmaPattern = /['"]use client['"]/;
|
|
40
|
-
const jsxElementPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*>([\s\S]*?)<\/\1>/;
|
|
41
|
-
const jsxSelfClosingPattern = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*\/?>/;
|
|
42
|
-
const jsxFragmentPattern = /<>([\s\S]*?)<\/>/;
|
|
43
|
-
const esbuildPlugin = () => ({
|
|
44
|
-
name: 'react-native-web',
|
|
45
|
-
setup: (build) => {
|
|
46
|
-
build.onLoad({ filter: reactNativeFlowJsxPathPattern }, async (args) => {
|
|
47
|
-
let contents = await fs.readFile(args.path, 'utf-8');
|
|
48
|
-
if (flowPragmaPattern.test(contents)) {
|
|
49
|
-
const transformed = flowRemoveTypes(contents);
|
|
50
|
-
contents = transformed.toString();
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
contents,
|
|
54
|
-
loader: reactNativeFlowJsxLoader,
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const reactNativeWeb = (options) => ({
|
|
60
|
-
enforce: 'pre',
|
|
61
|
-
name: 'react-native-web',
|
|
62
|
-
config: () => ({
|
|
63
|
-
define: {
|
|
64
|
-
global: 'globalThis',
|
|
65
|
-
__DEV__: JSON.stringify(development),
|
|
66
|
-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
67
|
-
'process.env.EXPO_OS': JSON.stringify('web'),
|
|
68
|
-
},
|
|
69
|
-
build: {
|
|
70
|
-
commonjsOptions: {
|
|
71
|
-
extensions,
|
|
72
|
-
transformMixedEsModules: true,
|
|
73
|
-
},
|
|
74
|
-
rollupOptions: (options === null || options === void 0 ? void 0 : options.enableExpoManualChunk) !== false
|
|
75
|
-
? {
|
|
76
|
-
output: {
|
|
77
|
-
manualChunks(id) {
|
|
78
|
-
if (id.includes('expo-modules-core')) {
|
|
79
|
-
return 'expo-modules-core';
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
entryFileNames: (chunk) => {
|
|
83
|
-
if (chunk.name === 'expo-modules-core') {
|
|
84
|
-
return '0-expo-modules-core.js';
|
|
85
|
-
}
|
|
86
|
-
return '[name].js';
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
: undefined,
|
|
91
|
-
},
|
|
92
|
-
resolve: {
|
|
93
|
-
extensions,
|
|
94
|
-
alias: [{ find: 'react-native', replacement: 'react-native-web' }],
|
|
95
|
-
},
|
|
96
|
-
optimizeDeps: {
|
|
97
|
-
esbuildOptions: {
|
|
98
|
-
plugins: [esbuildPlugin()],
|
|
99
|
-
resolveExtensions: extensions,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
async transform(code, id) {
|
|
104
|
-
id = id.split('?')[0];
|
|
105
|
-
if (!reactNativeFlowJsxPathPattern.test(id)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
let map = null;
|
|
109
|
-
if (flowPragmaPattern.test(code)) {
|
|
110
|
-
const transformed = flowRemoveTypes(code);
|
|
111
|
-
code = transformed.toString();
|
|
112
|
-
map = {
|
|
113
|
-
file: id,
|
|
114
|
-
toUrl: () => id,
|
|
115
|
-
...transformed.generateMap(),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (jsxElementPattern.test(code) || jsxSelfClosingPattern.test(code) || jsxFragmentPattern.test(code)) {
|
|
119
|
-
const result = await transformWithEsbuild(code, id, {
|
|
120
|
-
loader: reactNativeFlowJsxLoader,
|
|
121
|
-
tsconfigRaw: {
|
|
122
|
-
compilerOptions: {
|
|
123
|
-
jsx: 'react-jsx',
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
code = result.code;
|
|
128
|
-
map = result.map;
|
|
129
|
-
// 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)
|
|
130
|
-
if (useClientPragmaPattern.test(code)) {
|
|
131
|
-
map = null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return { code, map };
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
export { reactNativeWeb as default };
|
|
139
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|