vite-plugin-react-native-web 1.1.0 → 1.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 +86 -0
- package/dist/es/index.js +81 -0
- package/dist/es/package.json +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var vite = require('vite');
|
|
6
|
+
var flowRemoveTypes = require('flow-remove-types');
|
|
7
|
+
var fs = require('fs/promises');
|
|
8
|
+
|
|
9
|
+
// import type { ViteReactNativeWebOptions } from '../types'
|
|
10
|
+
const development = process.env.NODE_ENV === 'development';
|
|
11
|
+
const extensions = [
|
|
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
|
+
];
|
|
26
|
+
const loader = {
|
|
27
|
+
'.js': 'jsx',
|
|
28
|
+
};
|
|
29
|
+
const filter = /\.(js|flow)$/;
|
|
30
|
+
const esbuildPlugin = () => ({
|
|
31
|
+
name: 'react-native-web',
|
|
32
|
+
setup: build => {
|
|
33
|
+
build.onLoad({ filter }, async ({ path }) => {
|
|
34
|
+
const src = await fs.readFile(path, 'utf-8');
|
|
35
|
+
return {
|
|
36
|
+
contents: flowRemoveTypes(src).toString(),
|
|
37
|
+
loader: loader['.js'],
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
43
|
+
enforce: 'pre',
|
|
44
|
+
name: 'react-native-web',
|
|
45
|
+
config: () => ({
|
|
46
|
+
define: {
|
|
47
|
+
global: 'window',
|
|
48
|
+
__DEV__: JSON.stringify(development),
|
|
49
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
50
|
+
},
|
|
51
|
+
resolve: {
|
|
52
|
+
extensions,
|
|
53
|
+
alias: [{ find: 'react-native', replacement: 'react-native-web' }],
|
|
54
|
+
},
|
|
55
|
+
optimizeDeps: {
|
|
56
|
+
esbuildOptions: {
|
|
57
|
+
plugins: [esbuildPlugin()],
|
|
58
|
+
resolveExtensions: extensions,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
transform(code, id) {
|
|
63
|
+
if (!filter.test(id)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Skip files that are using 'use client' pragma since these break esbuild mappings (https://github.com/vitejs/vite/issues/15012)
|
|
67
|
+
if (code.includes('\'use client\'') || code.includes('"use client"')) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (code.includes('@flow')) {
|
|
71
|
+
code = flowRemoveTypes(code).toString();
|
|
72
|
+
}
|
|
73
|
+
return vite.transformWithEsbuild(code, id, {
|
|
74
|
+
loader: loader['.js'],
|
|
75
|
+
tsconfigRaw: {
|
|
76
|
+
compilerOptions: {
|
|
77
|
+
jsx: 'react-jsx',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
exports.default = reactNativeWeb;
|
|
85
|
+
module.exports = Object.assign(exports.default, exports);
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { transformWithEsbuild } from 'vite';
|
|
2
|
+
import flowRemoveTypes from 'flow-remove-types';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
// import type { ViteReactNativeWebOptions } from '../types'
|
|
6
|
+
const development = process.env.NODE_ENV === 'development';
|
|
7
|
+
const extensions = [
|
|
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
|
+
];
|
|
22
|
+
const loader = {
|
|
23
|
+
'.js': 'jsx',
|
|
24
|
+
};
|
|
25
|
+
const filter = /\.(js|flow)$/;
|
|
26
|
+
const esbuildPlugin = () => ({
|
|
27
|
+
name: 'react-native-web',
|
|
28
|
+
setup: build => {
|
|
29
|
+
build.onLoad({ filter }, async ({ path }) => {
|
|
30
|
+
const src = await fs.readFile(path, 'utf-8');
|
|
31
|
+
return {
|
|
32
|
+
contents: flowRemoveTypes(src).toString(),
|
|
33
|
+
loader: loader['.js'],
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const reactNativeWeb = ( /*options: ViteReactNativeWebOptions = {}*/) => ({
|
|
39
|
+
enforce: 'pre',
|
|
40
|
+
name: 'react-native-web',
|
|
41
|
+
config: () => ({
|
|
42
|
+
define: {
|
|
43
|
+
global: 'window',
|
|
44
|
+
__DEV__: JSON.stringify(development),
|
|
45
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
46
|
+
},
|
|
47
|
+
resolve: {
|
|
48
|
+
extensions,
|
|
49
|
+
alias: [{ find: 'react-native', replacement: 'react-native-web' }],
|
|
50
|
+
},
|
|
51
|
+
optimizeDeps: {
|
|
52
|
+
esbuildOptions: {
|
|
53
|
+
plugins: [esbuildPlugin()],
|
|
54
|
+
resolveExtensions: extensions,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
transform(code, id) {
|
|
59
|
+
if (!filter.test(id)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// Skip files that are using 'use client' pragma since these break esbuild mappings (https://github.com/vitejs/vite/issues/15012)
|
|
63
|
+
if (code.includes('\'use client\'') || code.includes('"use client"')) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (code.includes('@flow')) {
|
|
67
|
+
code = flowRemoveTypes(code).toString();
|
|
68
|
+
}
|
|
69
|
+
return transformWithEsbuild(code, id, {
|
|
70
|
+
loader: loader['.js'],
|
|
71
|
+
tsconfigRaw: {
|
|
72
|
+
compilerOptions: {
|
|
73
|
+
jsx: 'react-jsx',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export { reactNativeWeb as default };
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|