@tamagui/next-plugin 1.0.1-beta.215 → 1.0.1-beta.217
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 +28 -92
- package/dist/cjs/withTamagui.js.map +3 -3
- package/dist/esm/withTamagui.js +29 -93
- package/dist/esm/withTamagui.js.map +2 -2
- package/dist/jsx/withTamagui.js +29 -93
- package/dist/jsx/withTamagui.js.map +2 -2
- package/package.json +6 -8
- package/src/withTamagui.ts +36 -111
- package/types/withTamagui.d.ts +0 -1
package/dist/cjs/withTamagui.js
CHANGED
|
@@ -30,10 +30,7 @@ module.exports = __toCommonJS(withTamagui_exports);
|
|
|
30
30
|
var import_fs = require("fs");
|
|
31
31
|
var import_path = __toESM(require("path"));
|
|
32
32
|
var import_browserslist = __toESM(require("browserslist"));
|
|
33
|
-
var import_css_minimizer_webpack_plugin = __toESM(require("css-minimizer-webpack-plugin"));
|
|
34
33
|
var import_esm_resolve = __toESM(require("esm-resolve"));
|
|
35
|
-
var import_html_inline_css_webpack_plugin = __toESM(require("html-inline-css-webpack-plugin"));
|
|
36
|
-
var import_mini_css_extract_plugin = __toESM(require("mini-css-extract-plugin"));
|
|
37
34
|
var import_css = require("next/dist/build/webpack/config/blocks/css");
|
|
38
35
|
var import_loaders = require("next/dist/build/webpack/config/blocks/css/loaders");
|
|
39
36
|
var import_tamagui_loader = require("tamagui-loader");
|
|
@@ -160,11 +157,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
160
157
|
);
|
|
161
158
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports;
|
|
162
159
|
if (Array.isArray(excludeExports)) {
|
|
163
|
-
if (excludeExports.includes("PressResponder")) {
|
|
164
|
-
console.warn(
|
|
165
|
-
`\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
160
|
try {
|
|
169
161
|
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join("|")}).*js`;
|
|
170
162
|
const regex = new RegExp(regexStr);
|
|
@@ -186,22 +178,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
186
178
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
187
179
|
}
|
|
188
180
|
}
|
|
189
|
-
if (!dev) {
|
|
190
|
-
const cssMin = webpackConfig.optimization.minimizer.find(
|
|
191
|
-
(x) => x.toString().includes("css-minimizer-plugin")
|
|
192
|
-
);
|
|
193
|
-
if (cssMin) {
|
|
194
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
195
|
-
cssMin.index,
|
|
196
|
-
1
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
webpackConfig.optimization.minimizer.push(new import_css_minimizer_webpack_plugin.default());
|
|
200
|
-
}
|
|
201
|
-
webpackConfig.resolve.extensions = [
|
|
202
|
-
.../* @__PURE__ */ new Set([".web.tsx", ".web.ts", ".web.js", ...webpackConfig.resolve.extensions])
|
|
203
|
-
];
|
|
204
|
-
webpackConfig.resolve.mainFields.unshift("module:jsx");
|
|
205
181
|
if (isServer) {
|
|
206
182
|
const externalize = (context, request) => {
|
|
207
183
|
const fullPath = request[0] === "." ? import_path.default.join(context, request) : request;
|
|
@@ -262,18 +238,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
262
238
|
({ test }) => typeof test === "object" && typeof test.test === "function" && test.test("filename.css")
|
|
263
239
|
)
|
|
264
240
|
).oneOf;
|
|
265
|
-
const cssLoader = (0, import_loaders.getGlobalCssLoader)(
|
|
266
|
-
{
|
|
267
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
268
|
-
future: nextConfig.future,
|
|
269
|
-
experimental: nextConfig.experimental || {},
|
|
270
|
-
isClient: !isServer,
|
|
271
|
-
isServer,
|
|
272
|
-
isDevelopment: dev
|
|
273
|
-
},
|
|
274
|
-
() => (0, import_css.lazyPostCSS)(dir, getSupportedBrowsers(dir, dev)),
|
|
275
|
-
[]
|
|
276
|
-
);
|
|
277
241
|
if (cssRules) {
|
|
278
242
|
if (!tamaguiOptions.disableFontSupport) {
|
|
279
243
|
cssRules.unshift({
|
|
@@ -292,63 +256,35 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
292
256
|
]
|
|
293
257
|
});
|
|
294
258
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
test: cssTest,
|
|
300
|
-
use: [import_mini_css_extract_plugin.default.loader, "css-loader", postCSSLoader],
|
|
301
|
-
sideEffects: true
|
|
302
|
-
});
|
|
303
|
-
webpackConfig.plugins.push(
|
|
304
|
-
new import_mini_css_extract_plugin.default({
|
|
305
|
-
filename: "static/css/[contenthash].css",
|
|
306
|
-
ignoreOrder: true
|
|
307
|
-
})
|
|
308
|
-
);
|
|
309
|
-
if (tamaguiOptions.inlineCSS) {
|
|
310
|
-
webpackConfig.plugins.push(new import_html_inline_css_webpack_plugin.default());
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
cssRules.unshift({
|
|
314
|
-
test: cssTest,
|
|
315
|
-
sideEffects: true,
|
|
316
|
-
use: cssLoader
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf);
|
|
321
|
-
const oneOfJSRules = webpackConfig.module.rules[firstOneOfRule].oneOf;
|
|
322
|
-
const afterSWCLoaderIndex = oneOfJSRules.findIndex(
|
|
323
|
-
(x) => x && x.use && x.use.loader === "next-swc-loader" && x.issuerLayer !== "api"
|
|
324
|
-
) + 1;
|
|
325
|
-
const swcLoader = oneOfJSRules[afterSWCLoaderIndex];
|
|
326
|
-
oneOfJSRules.splice(
|
|
327
|
-
afterSWCLoaderIndex,
|
|
328
|
-
0,
|
|
329
|
-
{
|
|
330
|
-
test: /(bottom-sheet|react-native-reanimated).*\.[tj]sx?$/,
|
|
331
|
-
use: [
|
|
332
|
-
{
|
|
333
|
-
loader: "babel-loader",
|
|
334
|
-
options: {
|
|
335
|
-
presets: ["@babel/preset-react"],
|
|
336
|
-
plugins: ["react-native-reanimated/plugin"]
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
]
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
test: /\.(jsx?|tsx?)$/,
|
|
343
|
-
exclude: (path2) => shouldExclude(path2, options.dir),
|
|
344
|
-
use: [
|
|
345
|
-
...[].concat(swcLoader.use),
|
|
259
|
+
cssRules.unshift({
|
|
260
|
+
test: tamaguiOptions.includeCSSTest ?? /\.css$/,
|
|
261
|
+
sideEffects: true,
|
|
262
|
+
use: (0, import_loaders.getGlobalCssLoader)(
|
|
346
263
|
{
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
264
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
265
|
+
future: nextConfig.future,
|
|
266
|
+
experimental: nextConfig.experimental || {},
|
|
267
|
+
isEdgeRuntime: true,
|
|
268
|
+
isProduction: !dev,
|
|
269
|
+
targetWeb: true,
|
|
270
|
+
isClient: !isServer,
|
|
271
|
+
isServer,
|
|
272
|
+
isDevelopment: dev
|
|
273
|
+
},
|
|
274
|
+
() => (0, import_css.lazyPostCSS)(dir, getSupportedBrowsers(dir, dev)),
|
|
275
|
+
[]
|
|
276
|
+
)
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
webpackConfig.plugins.push(
|
|
280
|
+
new import_tamagui_loader.TamaguiPlugin({
|
|
281
|
+
commonjs: isServer,
|
|
282
|
+
exclude: (path2) => {
|
|
283
|
+
const res = shouldExclude(path2, options.dir);
|
|
284
|
+
return res;
|
|
285
|
+
},
|
|
286
|
+
...tamaguiOptions
|
|
287
|
+
})
|
|
352
288
|
);
|
|
353
289
|
if (typeof nextConfig.webpack === "function") {
|
|
354
290
|
return nextConfig.webpack(webpackConfig, options);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/withTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync } from 'fs'\nimport path, { dirname, join } from 'path'\n\nimport type { TamaguiOptions } from '@tamagui/static'\nimport browserslist from 'browserslist'\nimport CssMinimizerPlugin from 'css-minimizer-webpack-plugin'\nimport buildResolver from 'esm-resolve'\nimport InlineCSSPlugin from 'html-inline-css-webpack-plugin'\nimport MiniCSSExtractPlugin from 'mini-css-extract-plugin'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n inlineCSS?: boolean\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n if (excludeExports.includes('PressResponder')) {\n console.warn(\n `\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`\n )\n }\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n // TODO document and make configurable\n // replaces minifier with css-minimizer-webpack-plugin which handles deduping atomic styles\n if (!dev) {\n const cssMin = webpackConfig.optimization.minimizer.find((x) =>\n x.toString().includes('css-minimizer-plugin')\n )\n if (cssMin) {\n webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(\n cssMin.index,\n 1\n )\n }\n webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin())\n }\n\n webpackConfig.resolve.extensions = [\n ...new Set(['.web.tsx', '.web.ts', '.web.js', ...webpackConfig.resolve.extensions]),\n ]\n\n // look for compiled js with jsx intact as specified by module:jsx\n webpackConfig.resolve.mainFields.unshift('module:jsx')\n\n if (isServer) {\n const externalize = (context: string, request: string) => {\n const fullPath = request[0] === '.' ? path.join(context, request) : request\n\n if (tamaguiOptions.shouldExcludeFromServer) {\n const userRes = tamaguiOptions.shouldExcludeFromServer({\n context,\n request,\n fullPath,\n })\n if (userRes !== undefined) {\n return userRes\n }\n }\n\n if (isInComponentModule(fullPath)) {\n return false\n }\n\n if (fullPath.includes('react-native-web-lite')) {\n // always inline react-native-web-lite due to errors where next.js resolved the path to esm\n return false\n }\n\n // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith(`react-native${SEP}`)) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/lucide-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes(`node_modules${SEP}react-native-web`) ||\n new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.startsWith('moti') ||\n fullPath.startsWith('solito') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath === 'expo-linear-gradient' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath.startsWith('@gorhom')\n ) {\n return\n }\n if (/^@?react-native-/.test(request)) {\n return false\n }\n return true\n }\n\n // externalize react native things from bundle\n webpackConfig.externals = [\n ...webpackConfig.externals.map((external) => {\n if (typeof external !== 'function') {\n return external\n }\n // only runs on server\n return (ctx, cb) => {\n const isCb = typeof cb === 'function'\n const res = externalize(ctx.context, ctx.request)\n if (isCb) {\n if (typeof res === 'string') {\n return cb(null, res)\n }\n if (res) {\n return external(ctx, cb)\n }\n return cb()\n }\n return !res\n ? Promise.resolve(undefined)\n : typeof res === 'string'\n ? Promise.resolve(res)\n : external(ctx)\n }\n }),\n ]\n }\n\n const cssRules = webpackConfig.module.rules.find(\n (rule) =>\n Array.isArray(rule.oneOf) &&\n rule.oneOf.some(\n ({ test }) =>\n typeof test === 'object' &&\n typeof test.test === 'function' &&\n test.test('filename.css')\n )\n ).oneOf\n\n const cssLoader = getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n )\n\n if (cssRules) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n cssRules.unshift({\n test: /\\.(woff(2)?|eot|ttf|otf)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: nextConfig.inlineFontLimit || 1024,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n const cssTest = tamaguiOptions.includeCSSTest ?? /\\.css$/\n\n if (!dev) {\n const postCSSLoader = cssLoader[cssLoader.length - 1]\n // replace nextjs picky style rules with simple minicssextract\n cssRules.unshift({\n test: cssTest,\n use: [MiniCSSExtractPlugin.loader, 'css-loader', postCSSLoader],\n sideEffects: true,\n })\n webpackConfig.plugins.push(\n new MiniCSSExtractPlugin({\n filename: 'static/css/[contenthash].css',\n ignoreOrder: true,\n })\n )\n if (tamaguiOptions.inlineCSS) {\n webpackConfig.plugins.push(new InlineCSSPlugin())\n }\n } else {\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n }\n\n const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf)\n const oneOfJSRules: any[] = webpackConfig.module.rules[firstOneOfRule].oneOf\n const afterSWCLoaderIndex =\n oneOfJSRules.findIndex(\n (x) => x && x.use && x.use.loader === 'next-swc-loader' && x.issuerLayer !== 'api'\n ) + 1\n const swcLoader = oneOfJSRules[afterSWCLoaderIndex]\n\n // put an earlier loader where we just do tamagui stuff before regular swc\n oneOfJSRules.splice(\n afterSWCLoaderIndex,\n 0,\n {\n test: /(bottom-sheet|react-native-reanimated).*\\.[tj]sx?$/,\n use: [\n {\n loader: 'babel-loader',\n options: {\n presets: ['@babel/preset-react'],\n plugins: ['react-native-reanimated/plugin'],\n },\n },\n ],\n },\n {\n test: /\\.(jsx?|tsx?)$/,\n exclude: (path: string) => shouldExclude(path, options.dir),\n use: [\n ...[].concat(swcLoader.use),\n {\n loader: 'tamagui-loader',\n options: tamaguiOptions,\n },\n ],\n }\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {}\n\n return browsers\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["buildResolver", "_a", "path", "shouldExcludeDefault", "webpack", "
|
|
4
|
+
"sourcesContent": ["import { existsSync, fstat } from 'fs'\nimport path, { dirname, join } from 'path'\n\nimport type { TamaguiOptions } from '@tamagui/static'\nimport browserslist from 'browserslist'\nimport buildResolver from 'esm-resolve'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n if (isServer) {\n const externalize = (context: string, request: string) => {\n const fullPath = request[0] === '.' ? path.join(context, request) : request\n\n if (tamaguiOptions.shouldExcludeFromServer) {\n const userRes = tamaguiOptions.shouldExcludeFromServer({\n context,\n request,\n fullPath,\n })\n if (userRes !== undefined) {\n return userRes\n }\n }\n\n if (isInComponentModule(fullPath)) {\n return false\n }\n\n if (fullPath.includes('react-native-web-lite')) {\n // always inline react-native-web-lite due to errors where next.js resolved the path to esm\n return false\n }\n\n // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith(`react-native${SEP}`)) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/lucide-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes(`node_modules${SEP}react-native-web`) ||\n new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.startsWith('moti') ||\n fullPath.startsWith('solito') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath === 'expo-linear-gradient' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath.startsWith('@gorhom')\n ) {\n return\n }\n if (/^@?react-native-/.test(request)) {\n return false\n }\n return true\n }\n\n // externalize react native things from bundle\n webpackConfig.externals = [\n ...webpackConfig.externals.map((external) => {\n if (typeof external !== 'function') {\n return external\n }\n // only runs on server\n return (ctx, cb) => {\n const isCb = typeof cb === 'function'\n const res = externalize(ctx.context, ctx.request)\n if (isCb) {\n if (typeof res === 'string') {\n return cb(null, res)\n }\n if (res) {\n return external(ctx, cb)\n }\n return cb()\n }\n return !res\n ? Promise.resolve(undefined)\n : typeof res === 'string'\n ? Promise.resolve(res)\n : external(ctx)\n }\n }),\n ]\n }\n\n const cssRules = webpackConfig.module.rules.find(\n (rule) =>\n Array.isArray(rule.oneOf) &&\n rule.oneOf.some(\n ({ test }) =>\n typeof test === 'object' &&\n typeof test.test === 'function' &&\n test.test('filename.css')\n )\n ).oneOf\n\n if (cssRules) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n cssRules.unshift({\n test: /\\.(woff(2)?|eot|ttf|otf)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: nextConfig.inlineFontLimit || 1024,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n cssRules.unshift({\n test: tamaguiOptions.includeCSSTest ?? /\\.css$/,\n sideEffects: true,\n use: getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isEdgeRuntime: true,\n isProduction: !dev,\n targetWeb: true,\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n ),\n })\n }\n\n webpackConfig.plugins.push(\n new TamaguiPlugin({\n commonjs: isServer,\n exclude: (path: string) => {\n const res = shouldExclude(path, options.dir)\n // console.log(`shouldExclude`, res, path)\n return res\n },\n ...tamaguiOptions,\n })\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {\n //\n }\n return browsers\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,kBAAoC;AAGpC,0BAAyB;AACzB,yBAA0B;AAC1B,iBAA4B;AAC5B,qBAAmC;AACnC,4BAAqE;AACrE,qBAAoB;AAeb,MAAM,cAAc,CAAC,mBAAqC;AAC/D,SAAO,CAAC,aAAkB,CAAC,MAAM;AAC/B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,CAAC,eAAoB,YAAiB;AA5BrD;AA6BQ,cAAM,EAAE,KAAK,QAAQ,KAAK,S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AAc,CAAC;AAAA,gBACf,WAAW;AAAA,gBACX,UAAU,CAAC;AAAA,gBACX;AAAA,gBACA,eAAe;AAAA,cACjB;AAAA,cAEA,UAAM,wBAAY,KAAK,qBAAqB,KAAK,GAAG,CAAC;AAAA,cACrD,CAAC;AAAA,YACH;AAAA,UACF,CAAC;AAAA,QACH;AAEA,sBAAc,QAAQ;AAAA,UACpB,IAAI,oCAAc;AAAA,YAChB,UAAU;AAAA,YACV,SAAS,CAACA,UAAiB;AACzB,oBAAM,MAAM,cAAcA,OAAM,QAAQ,GAAG;AAE3C,qBAAO;AAAA,YACT;AAAA,YACA,GAAG;AAAA,UACL,CAAC;AAAA,QACH;AAEA,YAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,iBAAO,WAAW,QAAQ,eAAe,OAAO;AAAA,QAClD;AAEA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,qBAAqB,KAAK,eAAe;AAChD,MAAI;AACJ,MAAI;AACF,eAAW,oBAAAG,QAAa,WAAW;AAAA,MACjC,MAAM;AAAA,MACN,KAAK,gBAAgB,gBAAgB;AAAA,IACvC,CAAC;AAAA,EACH,QAAE;AAAA,EAEF;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["buildResolver", "_a", "path", "shouldExcludeDefault", "webpack", "browserslist"]
|
|
7
7
|
}
|
package/dist/esm/withTamagui.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import path, { dirname, join } from "path";
|
|
3
3
|
import browserslist from "browserslist";
|
|
4
|
-
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
5
4
|
import buildResolver from "esm-resolve";
|
|
6
|
-
import InlineCSSPlugin from "html-inline-css-webpack-plugin";
|
|
7
|
-
import MiniCSSExtractPlugin from "mini-css-extract-plugin";
|
|
8
5
|
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css";
|
|
9
6
|
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders";
|
|
10
|
-
import { shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
7
|
+
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
11
8
|
import webpack from "webpack";
|
|
12
9
|
const withTamagui = (tamaguiOptions) => {
|
|
13
10
|
return (nextConfig = {}) => {
|
|
@@ -131,11 +128,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
131
128
|
);
|
|
132
129
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports;
|
|
133
130
|
if (Array.isArray(excludeExports)) {
|
|
134
|
-
if (excludeExports.includes("PressResponder")) {
|
|
135
|
-
console.warn(
|
|
136
|
-
`\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
131
|
try {
|
|
140
132
|
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join("|")}).*js`;
|
|
141
133
|
const regex = new RegExp(regexStr);
|
|
@@ -157,22 +149,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
157
149
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
158
150
|
}
|
|
159
151
|
}
|
|
160
|
-
if (!dev) {
|
|
161
|
-
const cssMin = webpackConfig.optimization.minimizer.find(
|
|
162
|
-
(x) => x.toString().includes("css-minimizer-plugin")
|
|
163
|
-
);
|
|
164
|
-
if (cssMin) {
|
|
165
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
166
|
-
cssMin.index,
|
|
167
|
-
1
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin());
|
|
171
|
-
}
|
|
172
|
-
webpackConfig.resolve.extensions = [
|
|
173
|
-
.../* @__PURE__ */ new Set([".web.tsx", ".web.ts", ".web.js", ...webpackConfig.resolve.extensions])
|
|
174
|
-
];
|
|
175
|
-
webpackConfig.resolve.mainFields.unshift("module:jsx");
|
|
176
152
|
if (isServer) {
|
|
177
153
|
const externalize = (context, request) => {
|
|
178
154
|
const fullPath = request[0] === "." ? path.join(context, request) : request;
|
|
@@ -233,18 +209,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
233
209
|
({ test }) => typeof test === "object" && typeof test.test === "function" && test.test("filename.css")
|
|
234
210
|
)
|
|
235
211
|
).oneOf;
|
|
236
|
-
const cssLoader = getGlobalCssLoader(
|
|
237
|
-
{
|
|
238
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
239
|
-
future: nextConfig.future,
|
|
240
|
-
experimental: nextConfig.experimental || {},
|
|
241
|
-
isClient: !isServer,
|
|
242
|
-
isServer,
|
|
243
|
-
isDevelopment: dev
|
|
244
|
-
},
|
|
245
|
-
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
246
|
-
[]
|
|
247
|
-
);
|
|
248
212
|
if (cssRules) {
|
|
249
213
|
if (!tamaguiOptions.disableFontSupport) {
|
|
250
214
|
cssRules.unshift({
|
|
@@ -263,63 +227,35 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
263
227
|
]
|
|
264
228
|
});
|
|
265
229
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
test: cssTest,
|
|
271
|
-
use: [MiniCSSExtractPlugin.loader, "css-loader", postCSSLoader],
|
|
272
|
-
sideEffects: true
|
|
273
|
-
});
|
|
274
|
-
webpackConfig.plugins.push(
|
|
275
|
-
new MiniCSSExtractPlugin({
|
|
276
|
-
filename: "static/css/[contenthash].css",
|
|
277
|
-
ignoreOrder: true
|
|
278
|
-
})
|
|
279
|
-
);
|
|
280
|
-
if (tamaguiOptions.inlineCSS) {
|
|
281
|
-
webpackConfig.plugins.push(new InlineCSSPlugin());
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
cssRules.unshift({
|
|
285
|
-
test: cssTest,
|
|
286
|
-
sideEffects: true,
|
|
287
|
-
use: cssLoader
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf);
|
|
292
|
-
const oneOfJSRules = webpackConfig.module.rules[firstOneOfRule].oneOf;
|
|
293
|
-
const afterSWCLoaderIndex = oneOfJSRules.findIndex(
|
|
294
|
-
(x) => x && x.use && x.use.loader === "next-swc-loader" && x.issuerLayer !== "api"
|
|
295
|
-
) + 1;
|
|
296
|
-
const swcLoader = oneOfJSRules[afterSWCLoaderIndex];
|
|
297
|
-
oneOfJSRules.splice(
|
|
298
|
-
afterSWCLoaderIndex,
|
|
299
|
-
0,
|
|
300
|
-
{
|
|
301
|
-
test: /(bottom-sheet|react-native-reanimated).*\.[tj]sx?$/,
|
|
302
|
-
use: [
|
|
303
|
-
{
|
|
304
|
-
loader: "babel-loader",
|
|
305
|
-
options: {
|
|
306
|
-
presets: ["@babel/preset-react"],
|
|
307
|
-
plugins: ["react-native-reanimated/plugin"]
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
]
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
test: /\.(jsx?|tsx?)$/,
|
|
314
|
-
exclude: (path2) => shouldExclude(path2, options.dir),
|
|
315
|
-
use: [
|
|
316
|
-
...[].concat(swcLoader.use),
|
|
230
|
+
cssRules.unshift({
|
|
231
|
+
test: tamaguiOptions.includeCSSTest ?? /\.css$/,
|
|
232
|
+
sideEffects: true,
|
|
233
|
+
use: getGlobalCssLoader(
|
|
317
234
|
{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
235
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
236
|
+
future: nextConfig.future,
|
|
237
|
+
experimental: nextConfig.experimental || {},
|
|
238
|
+
isEdgeRuntime: true,
|
|
239
|
+
isProduction: !dev,
|
|
240
|
+
targetWeb: true,
|
|
241
|
+
isClient: !isServer,
|
|
242
|
+
isServer,
|
|
243
|
+
isDevelopment: dev
|
|
244
|
+
},
|
|
245
|
+
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
246
|
+
[]
|
|
247
|
+
)
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
webpackConfig.plugins.push(
|
|
251
|
+
new TamaguiPlugin({
|
|
252
|
+
commonjs: isServer,
|
|
253
|
+
exclude: (path2) => {
|
|
254
|
+
const res = shouldExclude(path2, options.dir);
|
|
255
|
+
return res;
|
|
256
|
+
},
|
|
257
|
+
...tamaguiOptions
|
|
258
|
+
})
|
|
323
259
|
);
|
|
324
260
|
if (typeof nextConfig.webpack === "function") {
|
|
325
261
|
return nextConfig.webpack(webpackConfig, options);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/withTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync } from 'fs'\nimport path, { dirname, join } from 'path'\n\nimport type { TamaguiOptions } from '@tamagui/static'\nimport browserslist from 'browserslist'\nimport CssMinimizerPlugin from 'css-minimizer-webpack-plugin'\nimport buildResolver from 'esm-resolve'\nimport InlineCSSPlugin from 'html-inline-css-webpack-plugin'\nimport MiniCSSExtractPlugin from 'mini-css-extract-plugin'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n inlineCSS?: boolean\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n if (excludeExports.includes('PressResponder')) {\n console.warn(\n `\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`\n )\n }\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n // TODO document and make configurable\n // replaces minifier with css-minimizer-webpack-plugin which handles deduping atomic styles\n if (!dev) {\n const cssMin = webpackConfig.optimization.minimizer.find((x) =>\n x.toString().includes('css-minimizer-plugin')\n )\n if (cssMin) {\n webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(\n cssMin.index,\n 1\n )\n }\n webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin())\n }\n\n webpackConfig.resolve.extensions = [\n ...new Set(['.web.tsx', '.web.ts', '.web.js', ...webpackConfig.resolve.extensions]),\n ]\n\n // look for compiled js with jsx intact as specified by module:jsx\n webpackConfig.resolve.mainFields.unshift('module:jsx')\n\n if (isServer) {\n const externalize = (context: string, request: string) => {\n const fullPath = request[0] === '.' ? path.join(context, request) : request\n\n if (tamaguiOptions.shouldExcludeFromServer) {\n const userRes = tamaguiOptions.shouldExcludeFromServer({\n context,\n request,\n fullPath,\n })\n if (userRes !== undefined) {\n return userRes\n }\n }\n\n if (isInComponentModule(fullPath)) {\n return false\n }\n\n if (fullPath.includes('react-native-web-lite')) {\n // always inline react-native-web-lite due to errors where next.js resolved the path to esm\n return false\n }\n\n // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith(`react-native${SEP}`)) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/lucide-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes(`node_modules${SEP}react-native-web`) ||\n new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.startsWith('moti') ||\n fullPath.startsWith('solito') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath === 'expo-linear-gradient' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath.startsWith('@gorhom')\n ) {\n return\n }\n if (/^@?react-native-/.test(request)) {\n return false\n }\n return true\n }\n\n // externalize react native things from bundle\n webpackConfig.externals = [\n ...webpackConfig.externals.map((external) => {\n if (typeof external !== 'function') {\n return external\n }\n // only runs on server\n return (ctx, cb) => {\n const isCb = typeof cb === 'function'\n const res = externalize(ctx.context, ctx.request)\n if (isCb) {\n if (typeof res === 'string') {\n return cb(null, res)\n }\n if (res) {\n return external(ctx, cb)\n }\n return cb()\n }\n return !res\n ? Promise.resolve(undefined)\n : typeof res === 'string'\n ? Promise.resolve(res)\n : external(ctx)\n }\n }),\n ]\n }\n\n const cssRules = webpackConfig.module.rules.find(\n (rule) =>\n Array.isArray(rule.oneOf) &&\n rule.oneOf.some(\n ({ test }) =>\n typeof test === 'object' &&\n typeof test.test === 'function' &&\n test.test('filename.css')\n )\n ).oneOf\n\n const cssLoader = getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n )\n\n if (cssRules) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n cssRules.unshift({\n test: /\\.(woff(2)?|eot|ttf|otf)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: nextConfig.inlineFontLimit || 1024,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n const cssTest = tamaguiOptions.includeCSSTest ?? /\\.css$/\n\n if (!dev) {\n const postCSSLoader = cssLoader[cssLoader.length - 1]\n // replace nextjs picky style rules with simple minicssextract\n cssRules.unshift({\n test: cssTest,\n use: [MiniCSSExtractPlugin.loader, 'css-loader', postCSSLoader],\n sideEffects: true,\n })\n webpackConfig.plugins.push(\n new MiniCSSExtractPlugin({\n filename: 'static/css/[contenthash].css',\n ignoreOrder: true,\n })\n )\n if (tamaguiOptions.inlineCSS) {\n webpackConfig.plugins.push(new InlineCSSPlugin())\n }\n } else {\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n }\n\n const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf)\n const oneOfJSRules: any[] = webpackConfig.module.rules[firstOneOfRule].oneOf\n const afterSWCLoaderIndex =\n oneOfJSRules.findIndex(\n (x) => x && x.use && x.use.loader === 'next-swc-loader' && x.issuerLayer !== 'api'\n ) + 1\n const swcLoader = oneOfJSRules[afterSWCLoaderIndex]\n\n // put an earlier loader where we just do tamagui stuff before regular swc\n oneOfJSRules.splice(\n afterSWCLoaderIndex,\n 0,\n {\n test: /(bottom-sheet|react-native-reanimated).*\\.[tj]sx?$/,\n use: [\n {\n loader: 'babel-loader',\n options: {\n presets: ['@babel/preset-react'],\n plugins: ['react-native-reanimated/plugin'],\n },\n },\n ],\n },\n {\n test: /\\.(jsx?|tsx?)$/,\n exclude: (path: string) => shouldExclude(path, options.dir),\n use: [\n ...[].concat(swcLoader.use),\n {\n loader: 'tamagui-loader',\n options: tamaguiOptions,\n },\n ],\n }\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {}\n\n return browsers\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { existsSync, fstat } from 'fs'\nimport path, { dirname, join } from 'path'\n\nimport type { TamaguiOptions } from '@tamagui/static'\nimport browserslist from 'browserslist'\nimport buildResolver from 'esm-resolve'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n if (isServer) {\n const externalize = (context: string, request: string) => {\n const fullPath = request[0] === '.' ? path.join(context, request) : request\n\n if (tamaguiOptions.shouldExcludeFromServer) {\n const userRes = tamaguiOptions.shouldExcludeFromServer({\n context,\n request,\n fullPath,\n })\n if (userRes !== undefined) {\n return userRes\n }\n }\n\n if (isInComponentModule(fullPath)) {\n return false\n }\n\n if (fullPath.includes('react-native-web-lite')) {\n // always inline react-native-web-lite due to errors where next.js resolved the path to esm\n return false\n }\n\n // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith(`react-native${SEP}`)) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/lucide-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes(`node_modules${SEP}react-native-web`) ||\n new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.startsWith('moti') ||\n fullPath.startsWith('solito') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath === 'expo-linear-gradient' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath.startsWith('@gorhom')\n ) {\n return\n }\n if (/^@?react-native-/.test(request)) {\n return false\n }\n return true\n }\n\n // externalize react native things from bundle\n webpackConfig.externals = [\n ...webpackConfig.externals.map((external) => {\n if (typeof external !== 'function') {\n return external\n }\n // only runs on server\n return (ctx, cb) => {\n const isCb = typeof cb === 'function'\n const res = externalize(ctx.context, ctx.request)\n if (isCb) {\n if (typeof res === 'string') {\n return cb(null, res)\n }\n if (res) {\n return external(ctx, cb)\n }\n return cb()\n }\n return !res\n ? Promise.resolve(undefined)\n : typeof res === 'string'\n ? Promise.resolve(res)\n : external(ctx)\n }\n }),\n ]\n }\n\n const cssRules = webpackConfig.module.rules.find(\n (rule) =>\n Array.isArray(rule.oneOf) &&\n rule.oneOf.some(\n ({ test }) =>\n typeof test === 'object' &&\n typeof test.test === 'function' &&\n test.test('filename.css')\n )\n ).oneOf\n\n if (cssRules) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n cssRules.unshift({\n test: /\\.(woff(2)?|eot|ttf|otf)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: nextConfig.inlineFontLimit || 1024,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n cssRules.unshift({\n test: tamaguiOptions.includeCSSTest ?? /\\.css$/,\n sideEffects: true,\n use: getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isEdgeRuntime: true,\n isProduction: !dev,\n targetWeb: true,\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n ),\n })\n }\n\n webpackConfig.plugins.push(\n new TamaguiPlugin({\n commonjs: isServer,\n exclude: (path: string) => {\n const res = shouldExclude(path, options.dir)\n // console.log(`shouldExclude`, res, path)\n return res\n },\n ...tamaguiOptions,\n })\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {\n //\n }\n return browsers\n}\n"],
|
|
5
|
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AAQ;AAAA,oBAClC,MAAM;AAAA,kBACR;AAAA,gBACF;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAEA,mBAAS,QAAQ;AAAA,YACf,MAAM,eAAe,kBAAkB;AAAA,YACvC,aAAa;AAAA,YACb,KAAK;AAAA,cAEH;AAAA,gBACE,aAAa,QAAQ,OAAO,eAAe,OAAO;AAAA,gBAClD,QAAQ,WAAW;AAAA,gBACnB,cAAc,WAAW,gBAAgB,CAAC;AAAA,gBAC1C,eAAe;AAAA,gBACf,cAAc,CAAC;AAAA,gBACf,WAAW;AAAA,gBACX,UAAU,CAAC;AAAA,gBACX;AAAA,gBACA,eAAe;AAAA,cACjB;AAAA,cAEA,MAAM,YAAY,KAAK,qBAAqB,KAAK,GAAG,CAAC;AAAA,cACrD,CAAC;AAAA,YACH;AAAA,UACF,CAAC;AAAA,QACH;AAEA,sBAAc,QAAQ;AAAA,UACpB,IAAI,cAAc;AAAA,YAChB,UAAU;AAAA,YACV,SAAS,CAACA,UAAiB;AACzB,oBAAM,MAAM,cAAcA,OAAM,QAAQ,GAAG;AAE3C,qBAAO;AAAA,YACT;AAAA,YACA,GAAG;AAAA,UACL,CAAC;AAAA,QACH;AAEA,YAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,iBAAO,WAAW,QAAQ,eAAe,OAAO;AAAA,QAClD;AAEA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,qBAAqB,KAAK,eAAe;AAChD,MAAI;AACJ,MAAI;AACF,eAAW,aAAa,WAAW;AAAA,MACjC,MAAM;AAAA,MACN,KAAK,gBAAgB,gBAAgB;AAAA,IACvC,CAAC;AAAA,EACH,QAAE;AAAA,EAEF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["_a", "path"]
|
|
7
7
|
}
|
package/dist/jsx/withTamagui.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import path, { dirname, join } from "path";
|
|
3
3
|
import browserslist from "browserslist";
|
|
4
|
-
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
5
4
|
import buildResolver from "esm-resolve";
|
|
6
|
-
import InlineCSSPlugin from "html-inline-css-webpack-plugin";
|
|
7
|
-
import MiniCSSExtractPlugin from "mini-css-extract-plugin";
|
|
8
5
|
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css";
|
|
9
6
|
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders";
|
|
10
|
-
import { shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
7
|
+
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
11
8
|
import webpack from "webpack";
|
|
12
9
|
const withTamagui = (tamaguiOptions) => {
|
|
13
10
|
return (nextConfig = {}) => {
|
|
@@ -128,11 +125,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
128
125
|
);
|
|
129
126
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports;
|
|
130
127
|
if (Array.isArray(excludeExports)) {
|
|
131
|
-
if (excludeExports.includes("PressResponder")) {
|
|
132
|
-
console.warn(
|
|
133
|
-
`\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
128
|
try {
|
|
137
129
|
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join("|")}).*js`;
|
|
138
130
|
const regex = new RegExp(regexStr);
|
|
@@ -154,22 +146,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
154
146
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
155
147
|
}
|
|
156
148
|
}
|
|
157
|
-
if (!dev) {
|
|
158
|
-
const cssMin = webpackConfig.optimization.minimizer.find(
|
|
159
|
-
(x) => x.toString().includes("css-minimizer-plugin")
|
|
160
|
-
);
|
|
161
|
-
if (cssMin) {
|
|
162
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
163
|
-
cssMin.index,
|
|
164
|
-
1
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin());
|
|
168
|
-
}
|
|
169
|
-
webpackConfig.resolve.extensions = [
|
|
170
|
-
.../* @__PURE__ */ new Set([".web.tsx", ".web.ts", ".web.js", ...webpackConfig.resolve.extensions])
|
|
171
|
-
];
|
|
172
|
-
webpackConfig.resolve.mainFields.unshift("module:jsx");
|
|
173
149
|
if (isServer) {
|
|
174
150
|
const externalize = (context, request) => {
|
|
175
151
|
const fullPath = request[0] === "." ? path.join(context, request) : request;
|
|
@@ -230,18 +206,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
230
206
|
({ test }) => typeof test === "object" && typeof test.test === "function" && test.test("filename.css")
|
|
231
207
|
)
|
|
232
208
|
).oneOf;
|
|
233
|
-
const cssLoader = getGlobalCssLoader(
|
|
234
|
-
{
|
|
235
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
236
|
-
future: nextConfig.future,
|
|
237
|
-
experimental: nextConfig.experimental || {},
|
|
238
|
-
isClient: !isServer,
|
|
239
|
-
isServer,
|
|
240
|
-
isDevelopment: dev
|
|
241
|
-
},
|
|
242
|
-
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
243
|
-
[]
|
|
244
|
-
);
|
|
245
209
|
if (cssRules) {
|
|
246
210
|
if (!tamaguiOptions.disableFontSupport) {
|
|
247
211
|
cssRules.unshift({
|
|
@@ -260,63 +224,35 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
260
224
|
]
|
|
261
225
|
});
|
|
262
226
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
test: cssTest,
|
|
268
|
-
use: [MiniCSSExtractPlugin.loader, "css-loader", postCSSLoader],
|
|
269
|
-
sideEffects: true
|
|
270
|
-
});
|
|
271
|
-
webpackConfig.plugins.push(
|
|
272
|
-
new MiniCSSExtractPlugin({
|
|
273
|
-
filename: "static/css/[contenthash].css",
|
|
274
|
-
ignoreOrder: true
|
|
275
|
-
})
|
|
276
|
-
);
|
|
277
|
-
if (tamaguiOptions.inlineCSS) {
|
|
278
|
-
webpackConfig.plugins.push(new InlineCSSPlugin());
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
cssRules.unshift({
|
|
282
|
-
test: cssTest,
|
|
283
|
-
sideEffects: true,
|
|
284
|
-
use: cssLoader
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf);
|
|
289
|
-
const oneOfJSRules = webpackConfig.module.rules[firstOneOfRule].oneOf;
|
|
290
|
-
const afterSWCLoaderIndex = oneOfJSRules.findIndex(
|
|
291
|
-
(x) => x && x.use && x.use.loader === "next-swc-loader" && x.issuerLayer !== "api"
|
|
292
|
-
) + 1;
|
|
293
|
-
const swcLoader = oneOfJSRules[afterSWCLoaderIndex];
|
|
294
|
-
oneOfJSRules.splice(
|
|
295
|
-
afterSWCLoaderIndex,
|
|
296
|
-
0,
|
|
297
|
-
{
|
|
298
|
-
test: /(bottom-sheet|react-native-reanimated).*\.[tj]sx?$/,
|
|
299
|
-
use: [
|
|
300
|
-
{
|
|
301
|
-
loader: "babel-loader",
|
|
302
|
-
options: {
|
|
303
|
-
presets: ["@babel/preset-react"],
|
|
304
|
-
plugins: ["react-native-reanimated/plugin"]
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
]
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
test: /\.(jsx?|tsx?)$/,
|
|
311
|
-
exclude: (path2) => shouldExclude(path2, options.dir),
|
|
312
|
-
use: [
|
|
313
|
-
...[].concat(swcLoader.use),
|
|
227
|
+
cssRules.unshift({
|
|
228
|
+
test: tamaguiOptions.includeCSSTest ?? /\.css$/,
|
|
229
|
+
sideEffects: true,
|
|
230
|
+
use: getGlobalCssLoader(
|
|
314
231
|
{
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
232
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
233
|
+
future: nextConfig.future,
|
|
234
|
+
experimental: nextConfig.experimental || {},
|
|
235
|
+
isEdgeRuntime: true,
|
|
236
|
+
isProduction: !dev,
|
|
237
|
+
targetWeb: true,
|
|
238
|
+
isClient: !isServer,
|
|
239
|
+
isServer,
|
|
240
|
+
isDevelopment: dev
|
|
241
|
+
},
|
|
242
|
+
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
243
|
+
[]
|
|
244
|
+
)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
webpackConfig.plugins.push(
|
|
248
|
+
new TamaguiPlugin({
|
|
249
|
+
commonjs: isServer,
|
|
250
|
+
exclude: (path2) => {
|
|
251
|
+
const res = shouldExclude(path2, options.dir);
|
|
252
|
+
return res;
|
|
253
|
+
},
|
|
254
|
+
...tamaguiOptions
|
|
255
|
+
})
|
|
320
256
|
);
|
|
321
257
|
if (typeof nextConfig.webpack === "function") {
|
|
322
258
|
return nextConfig.webpack(webpackConfig, options);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/withTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync } from 'fs'\nimport path, { dirname, join } from 'path'\n\nimport type { TamaguiOptions } from '@tamagui/static'\nimport browserslist from 'browserslist'\nimport CssMinimizerPlugin from 'css-minimizer-webpack-plugin'\nimport buildResolver from 'esm-resolve'\nimport InlineCSSPlugin from 'html-inline-css-webpack-plugin'\nimport MiniCSSExtractPlugin from 'mini-css-extract-plugin'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n inlineCSS?: boolean\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n if (excludeExports.includes('PressResponder')) {\n console.warn(\n `\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`\n )\n }\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n // TODO document and make configurable\n // replaces minifier with css-minimizer-webpack-plugin which handles deduping atomic styles\n if (!dev) {\n const cssMin = webpackConfig.optimization.minimizer.find((x) =>\n x.toString().includes('css-minimizer-plugin')\n )\n if (cssMin) {\n webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(\n cssMin.index,\n 1\n )\n }\n webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin())\n }\n\n webpackConfig.resolve.extensions = [\n ...new Set(['.web.tsx', '.web.ts', '.web.js', ...webpackConfig.resolve.extensions]),\n ]\n\n // look for compiled js with jsx intact as specified by module:jsx\n webpackConfig.resolve.mainFields.unshift('module:jsx')\n\n if (isServer) {\n const externalize = (context: string, request: string) => {\n const fullPath = request[0] === '.' ? path.join(context, request) : request\n\n if (tamaguiOptions.shouldExcludeFromServer) {\n const userRes = tamaguiOptions.shouldExcludeFromServer({\n context,\n request,\n fullPath,\n })\n if (userRes !== undefined) {\n return userRes\n }\n }\n\n if (isInComponentModule(fullPath)) {\n return false\n }\n\n if (fullPath.includes('react-native-web-lite')) {\n // always inline react-native-web-lite due to errors where next.js resolved the path to esm\n return false\n }\n\n // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith(`react-native${SEP}`)) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/lucide-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes(`node_modules${SEP}react-native-web`) ||\n new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.startsWith('moti') ||\n fullPath.startsWith('solito') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath === 'expo-linear-gradient' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath.startsWith('@gorhom')\n ) {\n return\n }\n if (/^@?react-native-/.test(request)) {\n return false\n }\n return true\n }\n\n // externalize react native things from bundle\n webpackConfig.externals = [\n ...webpackConfig.externals.map((external) => {\n if (typeof external !== 'function') {\n return external\n }\n // only runs on server\n return (ctx, cb) => {\n const isCb = typeof cb === 'function'\n const res = externalize(ctx.context, ctx.request)\n if (isCb) {\n if (typeof res === 'string') {\n return cb(null, res)\n }\n if (res) {\n return external(ctx, cb)\n }\n return cb()\n }\n return !res\n ? Promise.resolve(undefined)\n : typeof res === 'string'\n ? Promise.resolve(res)\n : external(ctx)\n }\n }),\n ]\n }\n\n const cssRules = webpackConfig.module.rules.find(\n (rule) =>\n Array.isArray(rule.oneOf) &&\n rule.oneOf.some(\n ({ test }) =>\n typeof test === 'object' &&\n typeof test.test === 'function' &&\n test.test('filename.css')\n )\n ).oneOf\n\n const cssLoader = getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n )\n\n if (cssRules) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n cssRules.unshift({\n test: /\\.(woff(2)?|eot|ttf|otf)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: nextConfig.inlineFontLimit || 1024,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n const cssTest = tamaguiOptions.includeCSSTest ?? /\\.css$/\n\n if (!dev) {\n const postCSSLoader = cssLoader[cssLoader.length - 1]\n // replace nextjs picky style rules with simple minicssextract\n cssRules.unshift({\n test: cssTest,\n use: [MiniCSSExtractPlugin.loader, 'css-loader', postCSSLoader],\n sideEffects: true,\n })\n webpackConfig.plugins.push(\n new MiniCSSExtractPlugin({\n filename: 'static/css/[contenthash].css',\n ignoreOrder: true,\n })\n )\n if (tamaguiOptions.inlineCSS) {\n webpackConfig.plugins.push(new InlineCSSPlugin())\n }\n } else {\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n }\n\n const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf)\n const oneOfJSRules: any[] = webpackConfig.module.rules[firstOneOfRule].oneOf\n const afterSWCLoaderIndex =\n oneOfJSRules.findIndex(\n (x) => x && x.use && x.use.loader === 'next-swc-loader' && x.issuerLayer !== 'api'\n ) + 1\n const swcLoader = oneOfJSRules[afterSWCLoaderIndex]\n\n // put an earlier loader where we just do tamagui stuff before regular swc\n oneOfJSRules.splice(\n afterSWCLoaderIndex,\n 0,\n {\n test: /(bottom-sheet|react-native-reanimated).*\\.[tj]sx?$/,\n use: [\n {\n loader: 'babel-loader',\n options: {\n presets: ['@babel/preset-react'],\n plugins: ['react-native-reanimated/plugin'],\n },\n },\n ],\n },\n {\n test: /\\.(jsx?|tsx?)$/,\n exclude: (path: string) => shouldExclude(path, options.dir),\n use: [\n ...[].concat(swcLoader.use),\n {\n loader: 'tamagui-loader',\n options: tamaguiOptions,\n },\n ],\n }\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {}\n\n return browsers\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { existsSync, fstat } from 'fs'\nimport path, { dirname, join } from 'path'\n\nimport type { TamaguiOptions } from '@tamagui/static'\nimport browserslist from 'browserslist'\nimport buildResolver from 'esm-resolve'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n if (isServer) {\n const externalize = (context: string, request: string) => {\n const fullPath = request[0] === '.' ? path.join(context, request) : request\n\n if (tamaguiOptions.shouldExcludeFromServer) {\n const userRes = tamaguiOptions.shouldExcludeFromServer({\n context,\n request,\n fullPath,\n })\n if (userRes !== undefined) {\n return userRes\n }\n }\n\n if (isInComponentModule(fullPath)) {\n return false\n }\n\n if (fullPath.includes('react-native-web-lite')) {\n // always inline react-native-web-lite due to errors where next.js resolved the path to esm\n return false\n }\n\n // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith(`react-native${SEP}`)) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/lucide-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes(`node_modules${SEP}react-native-web`) ||\n new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.startsWith('moti') ||\n fullPath.startsWith('solito') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath === 'expo-linear-gradient' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath.startsWith('@gorhom')\n ) {\n return\n }\n if (/^@?react-native-/.test(request)) {\n return false\n }\n return true\n }\n\n // externalize react native things from bundle\n webpackConfig.externals = [\n ...webpackConfig.externals.map((external) => {\n if (typeof external !== 'function') {\n return external\n }\n // only runs on server\n return (ctx, cb) => {\n const isCb = typeof cb === 'function'\n const res = externalize(ctx.context, ctx.request)\n if (isCb) {\n if (typeof res === 'string') {\n return cb(null, res)\n }\n if (res) {\n return external(ctx, cb)\n }\n return cb()\n }\n return !res\n ? Promise.resolve(undefined)\n : typeof res === 'string'\n ? Promise.resolve(res)\n : external(ctx)\n }\n }),\n ]\n }\n\n const cssRules = webpackConfig.module.rules.find(\n (rule) =>\n Array.isArray(rule.oneOf) &&\n rule.oneOf.some(\n ({ test }) =>\n typeof test === 'object' &&\n typeof test.test === 'function' &&\n test.test('filename.css')\n )\n ).oneOf\n\n if (cssRules) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n cssRules.unshift({\n test: /\\.(woff(2)?|eot|ttf|otf)(\\?v=\\d+\\.\\d+\\.\\d+)?$/,\n use: [\n {\n loader: require.resolve('url-loader'),\n options: {\n limit: nextConfig.inlineFontLimit || 1024,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n cssRules.unshift({\n test: tamaguiOptions.includeCSSTest ?? /\\.css$/,\n sideEffects: true,\n use: getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isEdgeRuntime: true,\n isProduction: !dev,\n targetWeb: true,\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n ),\n })\n }\n\n webpackConfig.plugins.push(\n new TamaguiPlugin({\n commonjs: isServer,\n exclude: (path: string) => {\n const res = shouldExclude(path, options.dir)\n // console.log(`shouldExclude`, res, path)\n return res\n },\n ...tamaguiOptions,\n })\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {\n //\n }\n return browsers\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAyB;AAClC,OAAO,QAAQ,SAAS,YAAY;AAGpC,OAAO,kBAAkB;AACzB,OAAO,mBAAmB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,eAAe,iBAAiB,4BAA4B;AACrE,OAAO,aAAa;AAeb,MAAM,cAAc,CAAC,mBAAqC;AAC/D,SAAO,CAAC,aAAkB,CAAC,MAAM;AAC/B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,CAAC,eAAoB,YAAiB;AAC7C,cAAM,EAAE,KAAK,QAAQ,KAAK,SAAS,IAAI;AAEvC,cAAM,WAAW,cAAc,KAAK,KAAK,UAAU,GAAG;AAAA,UACpD,aAAa;AAAA,QACf,CAAC;AAGD,YAAI,OAAO,WAAW,eAAe,aAAa;AAEhD,qBAAW,aAAa;AAAA,QAC1B;AAEA,cAAM,WAAW,OAAO,QAAQ,QAAQ,cAAc;AACtD,YAAI,CAAC,UAAU;AACb,gBAAM,IAAI,MAAM,2BAA2B;AAAA,QAC7C;AAEA,cAAM,SAAS,GAAG,WAAW,UAAU;AAEvC,cAAM,eAAe,IAAI,aAAiC;AACxD,gBAAM,MAAkB,CAAC;AACzB,qBAAW,CAAC,KAAK,GAAG,KAAK,UAAU;AACjC,gBAAI,IAAI,SAAS,GAAG,GAAG;AACrB,kBAAI,KAAK,CAAC,KAAK,GAAG,CAAC;AACnB;AAAA,YACF;AACA,gBAAI;AACF,kBAAI,KAAK,CAAC,KAAK,WAAW,GAAG,C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,EACH,QAAE;AAAA,EAEF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["path"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/next-plugin",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.217",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -22,25 +22,23 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/preset-react": "^7.18.6",
|
|
25
|
-
"@tamagui/proxy-worm": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/react-native-svg": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/static": "^1.0.1-beta.
|
|
25
|
+
"@tamagui/proxy-worm": "^1.0.1-beta.217",
|
|
26
|
+
"@tamagui/react-native-svg": "^1.0.1-beta.217",
|
|
27
|
+
"@tamagui/static": "^1.0.1-beta.217",
|
|
28
28
|
"babel-loader": "^8.2.5",
|
|
29
29
|
"browserslist": "^4.21.1",
|
|
30
30
|
"css-loader": "^5.2.4",
|
|
31
|
-
"css-minimizer-webpack-plugin": "^4.2.2",
|
|
32
31
|
"esbuild-loader": "^2.19.0",
|
|
33
32
|
"esm-resolve": "^1.0.8",
|
|
34
33
|
"file-loader": "^6.2.0",
|
|
35
34
|
"html-inline-css-webpack-plugin": "^1.11.1",
|
|
36
35
|
"html-webpack-plugin": "^5.5.0",
|
|
37
|
-
"
|
|
38
|
-
"tamagui-loader": "^1.0.1-beta.215",
|
|
36
|
+
"tamagui-loader": "^1.0.1-beta.217",
|
|
39
37
|
"thread-loader": "^3.0.4",
|
|
40
38
|
"url-loader": "^4.1.1"
|
|
41
39
|
},
|
|
42
40
|
"devDependencies": {
|
|
43
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
41
|
+
"@tamagui/build": "^1.0.1-beta.217",
|
|
44
42
|
"next": "^13.0.2"
|
|
45
43
|
},
|
|
46
44
|
"peerDependencies": {
|
package/src/withTamagui.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { existsSync } from 'fs'
|
|
1
|
+
import { existsSync, fstat } from 'fs'
|
|
2
2
|
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'
|
|
7
6
|
import buildResolver from 'esm-resolve'
|
|
8
|
-
import InlineCSSPlugin from 'html-inline-css-webpack-plugin'
|
|
9
|
-
import MiniCSSExtractPlugin from 'mini-css-extract-plugin'
|
|
10
7
|
import { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'
|
|
11
8
|
import { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'
|
|
12
|
-
import { shouldExclude as shouldExcludeDefault } from 'tamagui-loader'
|
|
9
|
+
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'
|
|
13
10
|
import webpack from 'webpack'
|
|
14
11
|
|
|
15
12
|
export type WithTamaguiProps = TamaguiOptions & {
|
|
@@ -17,7 +14,6 @@ export type WithTamaguiProps = TamaguiOptions & {
|
|
|
17
14
|
disableFontSupport?: boolean
|
|
18
15
|
aliasReactPackages?: boolean
|
|
19
16
|
includeCSSTest?: RegExp | ((path: string) => boolean)
|
|
20
|
-
inlineCSS?: boolean
|
|
21
17
|
shouldExtract?: (path: string, projectRoot: string) => boolean | undefined
|
|
22
18
|
shouldExcludeFromServer?: (props: {
|
|
23
19
|
context: string
|
|
@@ -175,11 +171,6 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
175
171
|
|
|
176
172
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports
|
|
177
173
|
if (Array.isArray(excludeExports)) {
|
|
178
|
-
if (excludeExports.includes('PressResponder')) {
|
|
179
|
-
console.warn(
|
|
180
|
-
`⚠️ Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
174
|
try {
|
|
184
175
|
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`
|
|
185
176
|
const regex = new RegExp(regexStr)
|
|
@@ -206,28 +197,6 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
206
197
|
}
|
|
207
198
|
}
|
|
208
199
|
|
|
209
|
-
// TODO document and make configurable
|
|
210
|
-
// replaces minifier with css-minimizer-webpack-plugin which handles deduping atomic styles
|
|
211
|
-
if (!dev) {
|
|
212
|
-
const cssMin = webpackConfig.optimization.minimizer.find((x) =>
|
|
213
|
-
x.toString().includes('css-minimizer-plugin')
|
|
214
|
-
)
|
|
215
|
-
if (cssMin) {
|
|
216
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
217
|
-
cssMin.index,
|
|
218
|
-
1
|
|
219
|
-
)
|
|
220
|
-
}
|
|
221
|
-
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin())
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
webpackConfig.resolve.extensions = [
|
|
225
|
-
...new Set(['.web.tsx', '.web.ts', '.web.js', ...webpackConfig.resolve.extensions]),
|
|
226
|
-
]
|
|
227
|
-
|
|
228
|
-
// look for compiled js with jsx intact as specified by module:jsx
|
|
229
|
-
webpackConfig.resolve.mainFields.unshift('module:jsx')
|
|
230
|
-
|
|
231
200
|
if (isServer) {
|
|
232
201
|
const externalize = (context: string, request: string) => {
|
|
233
202
|
const fullPath = request[0] === '.' ? path.join(context, request) : request
|
|
@@ -324,21 +293,6 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
324
293
|
)
|
|
325
294
|
).oneOf
|
|
326
295
|
|
|
327
|
-
const cssLoader = getGlobalCssLoader(
|
|
328
|
-
// @ts-ignore
|
|
329
|
-
{
|
|
330
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
331
|
-
future: nextConfig.future,
|
|
332
|
-
experimental: nextConfig.experimental || {},
|
|
333
|
-
isClient: !isServer,
|
|
334
|
-
isServer,
|
|
335
|
-
isDevelopment: dev,
|
|
336
|
-
},
|
|
337
|
-
// @ts-ignore
|
|
338
|
-
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
339
|
-
[]
|
|
340
|
-
)
|
|
341
|
-
|
|
342
296
|
if (cssRules) {
|
|
343
297
|
if (!tamaguiOptions.disableFontSupport) {
|
|
344
298
|
// fonts support
|
|
@@ -359,69 +313,39 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
359
313
|
})
|
|
360
314
|
}
|
|
361
315
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
cssRules.unshift({
|
|
368
|
-
test: cssTest,
|
|
369
|
-
use: [MiniCSSExtractPlugin.loader, 'css-loader', postCSSLoader],
|
|
370
|
-
sideEffects: true,
|
|
371
|
-
})
|
|
372
|
-
webpackConfig.plugins.push(
|
|
373
|
-
new MiniCSSExtractPlugin({
|
|
374
|
-
filename: 'static/css/[contenthash].css',
|
|
375
|
-
ignoreOrder: true,
|
|
376
|
-
})
|
|
377
|
-
)
|
|
378
|
-
if (tamaguiOptions.inlineCSS) {
|
|
379
|
-
webpackConfig.plugins.push(new InlineCSSPlugin())
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
cssRules.unshift({
|
|
383
|
-
test: cssTest,
|
|
384
|
-
sideEffects: true,
|
|
385
|
-
use: cssLoader,
|
|
386
|
-
})
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf)
|
|
391
|
-
const oneOfJSRules: any[] = webpackConfig.module.rules[firstOneOfRule].oneOf
|
|
392
|
-
const afterSWCLoaderIndex =
|
|
393
|
-
oneOfJSRules.findIndex(
|
|
394
|
-
(x) => x && x.use && x.use.loader === 'next-swc-loader' && x.issuerLayer !== 'api'
|
|
395
|
-
) + 1
|
|
396
|
-
const swcLoader = oneOfJSRules[afterSWCLoaderIndex]
|
|
397
|
-
|
|
398
|
-
// put an earlier loader where we just do tamagui stuff before regular swc
|
|
399
|
-
oneOfJSRules.splice(
|
|
400
|
-
afterSWCLoaderIndex,
|
|
401
|
-
0,
|
|
402
|
-
{
|
|
403
|
-
test: /(bottom-sheet|react-native-reanimated).*\.[tj]sx?$/,
|
|
404
|
-
use: [
|
|
405
|
-
{
|
|
406
|
-
loader: 'babel-loader',
|
|
407
|
-
options: {
|
|
408
|
-
presets: ['@babel/preset-react'],
|
|
409
|
-
plugins: ['react-native-reanimated/plugin'],
|
|
410
|
-
},
|
|
411
|
-
},
|
|
412
|
-
],
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
test: /\.(jsx?|tsx?)$/,
|
|
416
|
-
exclude: (path: string) => shouldExclude(path, options.dir),
|
|
417
|
-
use: [
|
|
418
|
-
...[].concat(swcLoader.use),
|
|
316
|
+
cssRules.unshift({
|
|
317
|
+
test: tamaguiOptions.includeCSSTest ?? /\.css$/,
|
|
318
|
+
sideEffects: true,
|
|
319
|
+
use: getGlobalCssLoader(
|
|
320
|
+
// @ts-ignore
|
|
419
321
|
{
|
|
420
|
-
|
|
421
|
-
|
|
322
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
323
|
+
future: nextConfig.future,
|
|
324
|
+
experimental: nextConfig.experimental || {},
|
|
325
|
+
isEdgeRuntime: true,
|
|
326
|
+
isProduction: !dev,
|
|
327
|
+
targetWeb: true,
|
|
328
|
+
isClient: !isServer,
|
|
329
|
+
isServer,
|
|
330
|
+
isDevelopment: dev,
|
|
422
331
|
},
|
|
423
|
-
|
|
424
|
-
|
|
332
|
+
// @ts-ignore
|
|
333
|
+
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
334
|
+
[]
|
|
335
|
+
),
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
webpackConfig.plugins.push(
|
|
340
|
+
new TamaguiPlugin({
|
|
341
|
+
commonjs: isServer,
|
|
342
|
+
exclude: (path: string) => {
|
|
343
|
+
const res = shouldExclude(path, options.dir)
|
|
344
|
+
// console.log(`shouldExclude`, res, path)
|
|
345
|
+
return res
|
|
346
|
+
},
|
|
347
|
+
...tamaguiOptions,
|
|
348
|
+
})
|
|
425
349
|
)
|
|
426
350
|
|
|
427
351
|
if (typeof nextConfig.webpack === 'function') {
|
|
@@ -441,7 +365,8 @@ function getSupportedBrowsers(dir, isDevelopment) {
|
|
|
441
365
|
path: dir,
|
|
442
366
|
env: isDevelopment ? 'development' : 'production',
|
|
443
367
|
})
|
|
444
|
-
} catch {
|
|
445
|
-
|
|
368
|
+
} catch {
|
|
369
|
+
//
|
|
370
|
+
}
|
|
446
371
|
return browsers
|
|
447
372
|
}
|
package/types/withTamagui.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export declare type WithTamaguiProps = TamaguiOptions & {
|
|
|
4
4
|
disableFontSupport?: boolean;
|
|
5
5
|
aliasReactPackages?: boolean;
|
|
6
6
|
includeCSSTest?: RegExp | ((path: string) => boolean);
|
|
7
|
-
inlineCSS?: boolean;
|
|
8
7
|
shouldExtract?: (path: string, projectRoot: string) => boolean | undefined;
|
|
9
8
|
shouldExcludeFromServer?: (props: {
|
|
10
9
|
context: string;
|