@tamagui/next-plugin 1.0.1-beta.226 → 1.0.1-beta.228
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/withTamagui.js +94 -53
- package/dist/cjs/withTamagui.js.map +3 -3
- package/dist/esm/withTamagui.js +94 -53
- package/dist/esm/withTamagui.js.map +2 -2
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/withTamagui.js +320 -0
- package/dist/jsx/withTamagui.js.map +7 -0
- package/package.json +8 -6
- package/src/withTamagui.ts +106 -59
- package/types/withTamagui.d.ts +1 -0
package/src/withTamagui.ts
CHANGED
|
@@ -3,7 +3,9 @@ import path, { dirname, join } from 'path'
|
|
|
3
3
|
|
|
4
4
|
import type { TamaguiOptions } from '@tamagui/static'
|
|
5
5
|
import browserslist from 'browserslist'
|
|
6
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
|
|
6
7
|
import buildResolver from 'esm-resolve'
|
|
8
|
+
import MiniCSSExtractPlugin from 'mini-css-extract-plugin'
|
|
7
9
|
import { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'
|
|
8
10
|
import { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'
|
|
9
11
|
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'
|
|
@@ -12,6 +14,7 @@ import webpack from 'webpack'
|
|
|
12
14
|
export type WithTamaguiProps = TamaguiOptions & {
|
|
13
15
|
useReactNativeWebLite: boolean
|
|
14
16
|
disableFontSupport?: boolean
|
|
17
|
+
enableCSSOptimizations?: boolean
|
|
15
18
|
aliasReactPackages?: boolean
|
|
16
19
|
includeCSSTest?: RegExp | ((path: string) => boolean)
|
|
17
20
|
shouldExtract?: (path: string, projectRoot: string) => boolean | undefined
|
|
@@ -46,7 +49,7 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
46
49
|
|
|
47
50
|
const prefix = `${isServer ? ' ssr ' : ' web '} |`
|
|
48
51
|
|
|
49
|
-
const safeResolves = (
|
|
52
|
+
const safeResolves = (resolves: [string, string][], multiple = false) => {
|
|
50
53
|
const res: string[][] = []
|
|
51
54
|
for (const [out, mod] of resolves) {
|
|
52
55
|
if (out.endsWith('$')) {
|
|
@@ -55,6 +58,9 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
55
58
|
}
|
|
56
59
|
try {
|
|
57
60
|
res.push([out, resolveEsm(mod)])
|
|
61
|
+
if (multiple) {
|
|
62
|
+
res.push([out, resolveEsm(mod, true)])
|
|
63
|
+
}
|
|
58
64
|
} catch (err) {
|
|
59
65
|
if (out.includes(`@gorhom/bottom-sheet`)) {
|
|
60
66
|
continue
|
|
@@ -65,11 +71,13 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
|
-
return
|
|
74
|
+
return res
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
const resolveEsm = (relativePath: string) => {
|
|
72
|
-
if (isServer
|
|
77
|
+
const resolveEsm = (relativePath: string, onlyRequire = false) => {
|
|
78
|
+
if (isServer || onlyRequire) {
|
|
79
|
+
return require.resolve(relativePath)
|
|
80
|
+
}
|
|
73
81
|
const esm = resolver(relativePath)
|
|
74
82
|
return esm ? path.join(dir, esm) : require.resolve(relativePath)
|
|
75
83
|
}
|
|
@@ -78,26 +86,25 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
78
86
|
|
|
79
87
|
// automatically compile our given components
|
|
80
88
|
const componentsFullPaths = safeResolves(
|
|
81
|
-
|
|
89
|
+
tamaguiOptions.components.map(
|
|
82
90
|
(moduleName) => [moduleName, moduleName] as [string, string]
|
|
83
|
-
)
|
|
91
|
+
),
|
|
92
|
+
true
|
|
84
93
|
)
|
|
85
94
|
|
|
86
|
-
const componentsBaseDirs =
|
|
87
|
-
(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
rootPath = join(rootPath, '..')
|
|
96
|
-
}
|
|
95
|
+
const componentsBaseDirs = componentsFullPaths.map(([_, fullPath]) => {
|
|
96
|
+
let rootPath = dirname(fullPath as string)
|
|
97
|
+
while (rootPath.length > 1) {
|
|
98
|
+
const pkg = join(rootPath, 'package.json')
|
|
99
|
+
const hasPkg = existsSync(pkg)
|
|
100
|
+
if (hasPkg) {
|
|
101
|
+
return rootPath
|
|
102
|
+
} else {
|
|
103
|
+
rootPath = join(rootPath, '..')
|
|
97
104
|
}
|
|
98
|
-
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)
|
|
99
105
|
}
|
|
100
|
-
|
|
106
|
+
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)
|
|
107
|
+
})
|
|
101
108
|
|
|
102
109
|
function isInComponentModule(fullPath: string) {
|
|
103
110
|
return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))
|
|
@@ -119,28 +126,30 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
119
126
|
? 'react-native-web-lite'
|
|
120
127
|
: 'react-native-web'
|
|
121
128
|
|
|
122
|
-
const tamaguiAliases =
|
|
123
|
-
[
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
const tamaguiAliases = Object.fromEntries(
|
|
130
|
+
safeResolves([
|
|
131
|
+
['@tamagui/core/reset.css', '@tamagui/core/reset.css'],
|
|
132
|
+
['@tamagui/core', '@tamagui/core'],
|
|
133
|
+
['react-native-svg', '@tamagui/react-native-svg'],
|
|
134
|
+
// fixes https://github.com/kentcdodds/mdx-bundler/issues/143
|
|
135
|
+
['react/jsx-runtime.js', 'react/jsx-runtime'],
|
|
136
|
+
['react/jsx-runtime', 'react/jsx-runtime'],
|
|
137
|
+
['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],
|
|
138
|
+
['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],
|
|
139
|
+
['react-native-reanimated', 'react-native-reanimated'],
|
|
140
|
+
['react-native$', rnw],
|
|
141
|
+
['react-native-web$', rnw],
|
|
142
|
+
['@testing-library/react-native', '@tamagui/proxy-worm'],
|
|
143
|
+
['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],
|
|
144
|
+
// fix reanimated 3
|
|
145
|
+
['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],
|
|
146
|
+
...(tamaguiOptions.aliasReactPackages
|
|
147
|
+
? ([
|
|
148
|
+
['react', 'react'],
|
|
149
|
+
['react-dom', 'react-dom'],
|
|
150
|
+
] as any)
|
|
151
|
+
: []),
|
|
152
|
+
])
|
|
144
153
|
)
|
|
145
154
|
|
|
146
155
|
const alias = {
|
|
@@ -197,6 +206,19 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
197
206
|
}
|
|
198
207
|
}
|
|
199
208
|
|
|
209
|
+
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
210
|
+
const cssMin = webpackConfig.optimization.minimizer.find((x) =>
|
|
211
|
+
x.toString().includes('css-minimizer-plugin')
|
|
212
|
+
)
|
|
213
|
+
if (cssMin) {
|
|
214
|
+
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
215
|
+
cssMin.index,
|
|
216
|
+
1
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin())
|
|
220
|
+
}
|
|
221
|
+
|
|
200
222
|
/**
|
|
201
223
|
* Server react-native compat
|
|
202
224
|
*/
|
|
@@ -322,26 +344,51 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
322
344
|
/**
|
|
323
345
|
* CSS Support
|
|
324
346
|
*/
|
|
347
|
+
const cssLoader = getGlobalCssLoader(
|
|
348
|
+
// @ts-ignore
|
|
349
|
+
{
|
|
350
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
351
|
+
future: nextConfig.future,
|
|
352
|
+
experimental: nextConfig.experimental || {},
|
|
353
|
+
isEdgeRuntime: true,
|
|
354
|
+
isProduction: !dev,
|
|
355
|
+
targetWeb: true,
|
|
356
|
+
isClient: !isServer,
|
|
357
|
+
isServer,
|
|
358
|
+
isDevelopment: dev,
|
|
359
|
+
},
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
362
|
+
[]
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
const cssTest = tamaguiOptions.includeCSSTest ?? /\.css$/
|
|
366
|
+
|
|
367
|
+
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
368
|
+
const postCSSLoader = cssLoader[cssLoader.length - 1]
|
|
369
|
+
// replace nextjs picky style rules with simple minicssextract
|
|
370
|
+
cssRules.unshift({
|
|
371
|
+
test: cssTest,
|
|
372
|
+
use: [MiniCSSExtractPlugin.loader, 'css-loader', postCSSLoader],
|
|
373
|
+
sideEffects: true,
|
|
374
|
+
})
|
|
375
|
+
webpackConfig.plugins.push(
|
|
376
|
+
new MiniCSSExtractPlugin({
|
|
377
|
+
filename: 'static/css/[contenthash].css',
|
|
378
|
+
ignoreOrder: true,
|
|
379
|
+
})
|
|
380
|
+
)
|
|
381
|
+
} else {
|
|
382
|
+
cssRules.unshift({
|
|
383
|
+
test: cssTest,
|
|
384
|
+
sideEffects: true,
|
|
385
|
+
use: cssLoader,
|
|
386
|
+
})
|
|
387
|
+
}
|
|
325
388
|
cssRules.unshift({
|
|
326
|
-
test:
|
|
389
|
+
test: cssTest,
|
|
327
390
|
sideEffects: true,
|
|
328
|
-
use:
|
|
329
|
-
// @ts-ignore
|
|
330
|
-
{
|
|
331
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
332
|
-
future: nextConfig.future,
|
|
333
|
-
experimental: nextConfig.experimental || {},
|
|
334
|
-
isEdgeRuntime: true,
|
|
335
|
-
isProduction: !dev,
|
|
336
|
-
targetWeb: true,
|
|
337
|
-
isClient: !isServer,
|
|
338
|
-
isServer,
|
|
339
|
-
isDevelopment: dev,
|
|
340
|
-
},
|
|
341
|
-
// @ts-ignore
|
|
342
|
-
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
343
|
-
[]
|
|
344
|
-
),
|
|
391
|
+
use: cssLoader,
|
|
345
392
|
})
|
|
346
393
|
}
|
|
347
394
|
|
package/types/withTamagui.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { TamaguiOptions } from '@tamagui/static';
|
|
|
2
2
|
export declare type WithTamaguiProps = TamaguiOptions & {
|
|
3
3
|
useReactNativeWebLite: boolean;
|
|
4
4
|
disableFontSupport?: boolean;
|
|
5
|
+
enableCSSOptimizations?: boolean;
|
|
5
6
|
aliasReactPackages?: boolean;
|
|
6
7
|
includeCSSTest?: RegExp | ((path: string) => boolean);
|
|
7
8
|
shouldExtract?: (path: string, projectRoot: string) => boolean | undefined;
|