vite-plugin-react-native-web 1.1.0 → 1.1.2
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 +91 -0
- package/dist/es/index.js +86 -0
- package/dist/es/package.json +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
async transform(code, id) {
|
|
63
|
+
if (!filter.test(id)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let includeSourceMaps = true;
|
|
67
|
+
// 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)
|
|
68
|
+
if (code.includes('\'use client\'') || code.includes('"use client"')) {
|
|
69
|
+
includeSourceMaps = false;
|
|
70
|
+
}
|
|
71
|
+
if (code.includes('@flow')) {
|
|
72
|
+
code = flowRemoveTypes(code).toString();
|
|
73
|
+
}
|
|
74
|
+
const result = await vite.transformWithEsbuild(code, id, {
|
|
75
|
+
loader: loader['.js'],
|
|
76
|
+
tsconfigRaw: {
|
|
77
|
+
compilerOptions: {
|
|
78
|
+
jsx: 'react-jsx',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
code: result.code,
|
|
84
|
+
map: includeSourceMaps ? result.map : null,
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
exports.default = reactNativeWeb;
|
|
90
|
+
module.exports = Object.assign(exports.default, exports);
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
async transform(code, id) {
|
|
59
|
+
if (!filter.test(id)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let includeSourceMaps = true;
|
|
63
|
+
// 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)
|
|
64
|
+
if (code.includes('\'use client\'') || code.includes('"use client"')) {
|
|
65
|
+
includeSourceMaps = false;
|
|
66
|
+
}
|
|
67
|
+
if (code.includes('@flow')) {
|
|
68
|
+
code = flowRemoveTypes(code).toString();
|
|
69
|
+
}
|
|
70
|
+
const result = await transformWithEsbuild(code, id, {
|
|
71
|
+
loader: loader['.js'],
|
|
72
|
+
tsconfigRaw: {
|
|
73
|
+
compilerOptions: {
|
|
74
|
+
jsx: 'react-jsx',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
code: result.code,
|
|
80
|
+
map: includeSourceMaps ? result.map : null,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export { reactNativeWeb as default };
|
|
86
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|