@tamagui/next-plugin 1.0.1-rc.1.4 → 1.0.1-rc.10
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 +14 -40
- package/dist/cjs/withTamagui.js.map +3 -3
- package/dist/esm/withTamagui.js +14 -40
- package/dist/esm/withTamagui.js.map +2 -2
- package/dist/jsx/index.js +4 -0
- package/dist/jsx/index.js.map +2 -2
- package/dist/jsx/withTamagui.js +130 -170
- package/dist/jsx/withTamagui.js.map +3 -3
- package/package.json +8 -11
- package/src/withTamagui.ts +26 -47
- package/types/withTamagui.d.ts +0 -1
package/dist/cjs/withTamagui.js
CHANGED
|
@@ -30,9 +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_mini_css_extract_plugin = __toESM(require("mini-css-extract-plugin"));
|
|
36
34
|
var import_css = require("next/dist/build/webpack/config/blocks/css");
|
|
37
35
|
var import_loaders = require("next/dist/build/webpack/config/blocks/css/loaders");
|
|
38
36
|
var import_tamagui_loader = require("tamagui-loader");
|
|
@@ -107,7 +105,9 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
107
105
|
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
108
106
|
});
|
|
109
107
|
function isInComponentModule(fullPath) {
|
|
110
|
-
return componentsBaseDirs.some(
|
|
108
|
+
return componentsBaseDirs.some(
|
|
109
|
+
(componentDir) => fullPath.startsWith(componentDir)
|
|
110
|
+
);
|
|
111
111
|
}
|
|
112
112
|
const shouldExclude = (path2, projectRoot) => {
|
|
113
113
|
var _a2;
|
|
@@ -165,14 +165,21 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
165
165
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports;
|
|
166
166
|
if (Array.isArray(excludeExports)) {
|
|
167
167
|
try {
|
|
168
|
-
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join(
|
|
168
|
+
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join(
|
|
169
|
+
"|"
|
|
170
|
+
)}).*js`;
|
|
169
171
|
const regex = new RegExp(regexStr);
|
|
170
172
|
webpackConfig.plugins.push(
|
|
171
|
-
new import_webpack.default.NormalModuleReplacementPlugin(
|
|
173
|
+
new import_webpack.default.NormalModuleReplacementPlugin(
|
|
174
|
+
regex,
|
|
175
|
+
resolveEsm("@tamagui/proxy-worm")
|
|
176
|
+
)
|
|
172
177
|
);
|
|
173
178
|
} catch (err) {
|
|
174
179
|
console.warn(
|
|
175
|
-
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(
|
|
180
|
+
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(
|
|
181
|
+
", "
|
|
182
|
+
)}`
|
|
176
183
|
);
|
|
177
184
|
}
|
|
178
185
|
}
|
|
@@ -185,18 +192,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
185
192
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
186
193
|
}
|
|
187
194
|
}
|
|
188
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
189
|
-
const cssMin = webpackConfig.optimization.minimizer.find(
|
|
190
|
-
(x) => x.toString().includes("css-minimizer-plugin")
|
|
191
|
-
);
|
|
192
|
-
if (cssMin) {
|
|
193
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
194
|
-
cssMin.index,
|
|
195
|
-
1
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
webpackConfig.optimization.minimizer.push(new import_css_minimizer_webpack_plugin.default());
|
|
199
|
-
}
|
|
200
195
|
if (isServer) {
|
|
201
196
|
const externalize = (context, request) => {
|
|
202
197
|
const fullPath = request[0] === "." ? import_path.default.join(context, request) : request;
|
|
@@ -290,29 +285,8 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
290
285
|
() => (0, import_css.lazyPostCSS)(dir, getSupportedBrowsers(dir, dev)),
|
|
291
286
|
[]
|
|
292
287
|
);
|
|
293
|
-
const cssTest = tamaguiOptions.includeCSSTest ?? /\.tamagui\.css$/;
|
|
294
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
295
|
-
const postCSSLoader = cssLoader[cssLoader.length - 1];
|
|
296
|
-
cssRules.unshift({
|
|
297
|
-
test: cssTest,
|
|
298
|
-
use: [import_mini_css_extract_plugin.default.loader, "css-loader", postCSSLoader],
|
|
299
|
-
sideEffects: true
|
|
300
|
-
});
|
|
301
|
-
webpackConfig.plugins.push(
|
|
302
|
-
new import_mini_css_extract_plugin.default({
|
|
303
|
-
filename: "static/css/[contenthash].css",
|
|
304
|
-
ignoreOrder: true
|
|
305
|
-
})
|
|
306
|
-
);
|
|
307
|
-
} else {
|
|
308
|
-
cssRules.unshift({
|
|
309
|
-
test: cssTest,
|
|
310
|
-
sideEffects: true,
|
|
311
|
-
use: cssLoader
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
288
|
cssRules.unshift({
|
|
315
|
-
test:
|
|
289
|
+
test: tamaguiOptions.includeCSSTest ?? /\.tamagui\.css$/,
|
|
316
290
|
sideEffects: true,
|
|
317
291
|
use: cssLoader
|
|
318
292
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/withTamagui.ts"],
|
|
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 CssMinimizerPlugin from 'css-minimizer-webpack-plugin'\nimport buildResolver from 'esm-resolve'\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 { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n enableCSSOptimizations?: 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][], multiple = false) => {\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 if (multiple) {\n res.push([out, resolveEsm(mod, true)])\n }\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 res\n }\n\n const resolveEsm = (relativePath: string, onlyRequire = false) => {\n if (isServer || onlyRequire) {\n return require.resolve(relativePath)\n }\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 true\n )\n\n const componentsBaseDirs = componentsFullPaths.map(([_, 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 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 = Object.fromEntries(\n 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\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 (!dev && tamaguiOptions.enableCSSOptimizations) {\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 /**\n * Server react-native compat\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 /**\n * Font Support\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 /**\n * CSS Support\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 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 const cssTest = tamaguiOptions.includeCSSTest ?? /\\.tamagui\\.css$/\n\n if (!dev && tamaguiOptions.enableCSSOptimizations) {\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 } else {\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\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,
|
|
6
|
-
"names": ["buildResolver", "_a", "path", "shouldExcludeDefault", "webpack", "
|
|
4
|
+
"sourcesContent": ["import { existsSync } 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][], multiple = false) => {\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 if (multiple) {\n res.push([out, resolveEsm(mod, true)])\n }\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 res\n }\n\n const resolveEsm = (relativePath: string, onlyRequire = false) => {\n if (isServer || onlyRequire) {\n return require.resolve(relativePath)\n }\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 true\n )\n\n const componentsBaseDirs = componentsFullPaths.map(([_, 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 function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) =>\n fullPath.startsWith(componentDir)\n )\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 = Object.fromEntries(\n safeResolves([\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n // web specific light react-native-svg, optional, can use svgs but had issues with compat\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\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(\n '|'\n )}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(\n regex,\n resolveEsm('@tamagui/proxy-worm')\n )\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 }\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 /**\n * Server react-native compat\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 (\n fullPath === 'react-native' ||\n fullPath.startsWith(`react-native${SEP}`)\n ) {\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 /**\n * Non-server support\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 /**\n * Font Support\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: `${\n nextConfig.assetPrefix || ''\n }/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n /**\n * CSS Support\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 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 cssRules.unshift({\n test: tamaguiOptions.includeCSSTest ?? /\\.tamagui\\.css$/,\n sideEffects: true,\n use: cssLoader,\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,gBAA2B;AAC3B,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,SAAS,IAAI;AAEvC,cAAM,eAAW,mBAAAA,aAAc,kBAAK,KAAK,UAAU,GAAG;AAAA,UACpD,aAAa;AAAA,QACf,CAAC;AAGD,YAAI,OAAO,WAAW,eAAe,aAAa;AAEhD,qBAAW,aAAa;AAAA,QAC1B;AAEA,cAAM,WAAW,SAAO,aAAQ,WAAR,mBAAgB,eAAc;AACtD,YAAI,CAAC,UAAU;AACb,gBAAM,IAAI,MAAM,2BAA2B;AAAA,QAC7C;AAEA,cAAM,SAAS,GAAG,WAAW,UAAU;AAEvC,cAAM,eAAe,CAAC,UAA8B,WAAW,UAAU;AAhDjF,cAAAC;AAiDU,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,CAAC,CAAC;AAC/B,kBAAI,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,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,9 +1,7 @@
|
|
|
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 MiniCSSExtractPlugin from "mini-css-extract-plugin";
|
|
7
5
|
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css";
|
|
8
6
|
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders";
|
|
9
7
|
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
@@ -78,7 +76,9 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
78
76
|
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
79
77
|
});
|
|
80
78
|
function isInComponentModule(fullPath) {
|
|
81
|
-
return componentsBaseDirs.some(
|
|
79
|
+
return componentsBaseDirs.some(
|
|
80
|
+
(componentDir) => fullPath.startsWith(componentDir)
|
|
81
|
+
);
|
|
82
82
|
}
|
|
83
83
|
const shouldExclude = (path2, projectRoot) => {
|
|
84
84
|
var _a2;
|
|
@@ -136,14 +136,21 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
136
136
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports;
|
|
137
137
|
if (Array.isArray(excludeExports)) {
|
|
138
138
|
try {
|
|
139
|
-
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join(
|
|
139
|
+
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join(
|
|
140
|
+
"|"
|
|
141
|
+
)}).*js`;
|
|
140
142
|
const regex = new RegExp(regexStr);
|
|
141
143
|
webpackConfig.plugins.push(
|
|
142
|
-
new webpack.NormalModuleReplacementPlugin(
|
|
144
|
+
new webpack.NormalModuleReplacementPlugin(
|
|
145
|
+
regex,
|
|
146
|
+
resolveEsm("@tamagui/proxy-worm")
|
|
147
|
+
)
|
|
143
148
|
);
|
|
144
149
|
} catch (err) {
|
|
145
150
|
console.warn(
|
|
146
|
-
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(
|
|
151
|
+
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(
|
|
152
|
+
", "
|
|
153
|
+
)}`
|
|
147
154
|
);
|
|
148
155
|
}
|
|
149
156
|
}
|
|
@@ -156,18 +163,6 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
156
163
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
160
|
-
const cssMin = webpackConfig.optimization.minimizer.find(
|
|
161
|
-
(x) => x.toString().includes("css-minimizer-plugin")
|
|
162
|
-
);
|
|
163
|
-
if (cssMin) {
|
|
164
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
165
|
-
cssMin.index,
|
|
166
|
-
1
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin());
|
|
170
|
-
}
|
|
171
166
|
if (isServer) {
|
|
172
167
|
const externalize = (context, request) => {
|
|
173
168
|
const fullPath = request[0] === "." ? path.join(context, request) : request;
|
|
@@ -261,29 +256,8 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
261
256
|
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
262
257
|
[]
|
|
263
258
|
);
|
|
264
|
-
const cssTest = tamaguiOptions.includeCSSTest ?? /\.tamagui\.css$/;
|
|
265
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
266
|
-
const postCSSLoader = cssLoader[cssLoader.length - 1];
|
|
267
|
-
cssRules.unshift({
|
|
268
|
-
test: cssTest,
|
|
269
|
-
use: [MiniCSSExtractPlugin.loader, "css-loader", postCSSLoader],
|
|
270
|
-
sideEffects: true
|
|
271
|
-
});
|
|
272
|
-
webpackConfig.plugins.push(
|
|
273
|
-
new MiniCSSExtractPlugin({
|
|
274
|
-
filename: "static/css/[contenthash].css",
|
|
275
|
-
ignoreOrder: true
|
|
276
|
-
})
|
|
277
|
-
);
|
|
278
|
-
} else {
|
|
279
|
-
cssRules.unshift({
|
|
280
|
-
test: cssTest,
|
|
281
|
-
sideEffects: true,
|
|
282
|
-
use: cssLoader
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
259
|
cssRules.unshift({
|
|
286
|
-
test:
|
|
260
|
+
test: tamaguiOptions.includeCSSTest ?? /\.tamagui\.css$/,
|
|
287
261
|
sideEffects: true,
|
|
288
262
|
use: cssLoader
|
|
289
263
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/withTamagui.ts"],
|
|
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 CssMinimizerPlugin from 'css-minimizer-webpack-plugin'\nimport buildResolver from 'esm-resolve'\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 { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n enableCSSOptimizations?: 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][], multiple = false) => {\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 if (multiple) {\n res.push([out, resolveEsm(mod, true)])\n }\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 res\n }\n\n const resolveEsm = (relativePath: string, onlyRequire = false) => {\n if (isServer || onlyRequire) {\n return require.resolve(relativePath)\n }\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 true\n )\n\n const componentsBaseDirs = componentsFullPaths.map(([_, 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 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 = Object.fromEntries(\n 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\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 (!dev && tamaguiOptions.enableCSSOptimizations) {\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 /**\n * Server react-native compat\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 /**\n * Font Support\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 /**\n * CSS Support\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 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 const cssTest = tamaguiOptions.includeCSSTest ?? /\\.tamagui\\.css$/\n\n if (!dev && tamaguiOptions.enableCSSOptimizations) {\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 } else {\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\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,
|
|
4
|
+
"sourcesContent": ["import { existsSync } 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][], multiple = false) => {\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 if (multiple) {\n res.push([out, resolveEsm(mod, true)])\n }\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 res\n }\n\n const resolveEsm = (relativePath: string, onlyRequire = false) => {\n if (isServer || onlyRequire) {\n return require.resolve(relativePath)\n }\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 true\n )\n\n const componentsBaseDirs = componentsFullPaths.map(([_, 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 function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) =>\n fullPath.startsWith(componentDir)\n )\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 = Object.fromEntries(\n safeResolves([\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n // web specific light react-native-svg, optional, can use svgs but had issues with compat\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\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(\n '|'\n )}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(\n regex,\n resolveEsm('@tamagui/proxy-worm')\n )\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 }\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 /**\n * Server react-native compat\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 (\n fullPath === 'react-native' ||\n fullPath.startsWith(`react-native${SEP}`)\n ) {\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 /**\n * Non-server support\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 /**\n * Font Support\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: `${\n nextConfig.assetPrefix || ''\n }/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name].[ext]',\n },\n },\n ],\n })\n }\n\n /**\n * CSS Support\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 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 cssRules.unshift({\n test: tamaguiOptions.includeCSSTest ?? /\\.tamagui\\.css$/,\n sideEffects: true,\n use: cssLoader,\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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AA,EAEF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["_a", "path"]
|
|
7
7
|
}
|
package/dist/jsx/index.js
CHANGED
package/dist/jsx/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './withTamagui'\n"],
|
|
5
|
-
"mappings": "AAAA
|
|
4
|
+
"sourcesContent": ["export * from './withTamagui'\n\n// this applies automatically already!\n// only exported necessary for weird/advanced use cases, where\n// your react-native-web is in some other directory\nexport { patchReactNativeWeb } from '@tamagui/static'\n"],
|
|
5
|
+
"mappings": "AAAA;AAKA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/withTamagui.js
CHANGED
|
@@ -1,147 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import path, { dirname, join } from "path";
|
|
1
|
+
import path, { join } from "path";
|
|
3
2
|
import browserslist from "browserslist";
|
|
4
3
|
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
5
4
|
import buildResolver from "esm-resolve";
|
|
5
|
+
import InlineCSSPlugin from "html-inline-css-webpack-plugin";
|
|
6
6
|
import MiniCSSExtractPlugin from "mini-css-extract-plugin";
|
|
7
7
|
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css";
|
|
8
8
|
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders";
|
|
9
|
-
import {
|
|
9
|
+
import { shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
10
10
|
import webpack from "webpack";
|
|
11
11
|
const withTamagui = (tamaguiOptions) => {
|
|
12
|
+
const shouldExclude = (path2, projectRoot) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const res = (_a = tamaguiOptions.shouldExtract) == null ? void 0 : _a.call(tamaguiOptions, path2, projectRoot);
|
|
15
|
+
if (typeof res === "boolean") {
|
|
16
|
+
return !res;
|
|
17
|
+
}
|
|
18
|
+
return shouldExcludeDefault(path2, projectRoot);
|
|
19
|
+
};
|
|
12
20
|
return (nextConfig = {}) => {
|
|
13
21
|
return {
|
|
14
22
|
...nextConfig,
|
|
15
23
|
webpack: (webpackConfig, options) => {
|
|
24
|
+
var _a, _b;
|
|
16
25
|
const { dir, config, dev, isServer } = options;
|
|
17
26
|
const resolver = buildResolver(join(dir, "index.js"), {
|
|
18
27
|
constraints: "node"
|
|
19
28
|
});
|
|
29
|
+
const resolveEsm = (relativePath) => {
|
|
30
|
+
if (isServer)
|
|
31
|
+
return require.resolve(relativePath);
|
|
32
|
+
const esm = resolver(relativePath);
|
|
33
|
+
return esm ? path.join(dir, esm) : require.resolve(relativePath);
|
|
34
|
+
};
|
|
20
35
|
if (typeof globalThis["__DEV__"] === "undefined") {
|
|
21
36
|
globalThis["__DEV__"] = dev;
|
|
22
37
|
}
|
|
23
|
-
const isNext12 = typeof options.config
|
|
24
|
-
if (!isNext12) {
|
|
25
|
-
throw new Error(`Next.js 12 only supported`);
|
|
26
|
-
}
|
|
38
|
+
const isNext12 = typeof ((_a = options.config) == null ? void 0 : _a.swcMinify) === "boolean";
|
|
27
39
|
const prefix = `${isServer ? " ssr " : " web "} |`;
|
|
28
|
-
const safeResolves = (resolves
|
|
40
|
+
const safeResolves = (...resolves) => {
|
|
29
41
|
const res = [];
|
|
30
42
|
for (const [out, mod] of resolves) {
|
|
31
|
-
if (out.endsWith("$")) {
|
|
32
|
-
res.push([out, mod]);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
43
|
try {
|
|
36
44
|
res.push([out, resolveEsm(mod)]);
|
|
37
|
-
if (multiple) {
|
|
38
|
-
res.push([out, resolveEsm(mod, true)]);
|
|
39
|
-
}
|
|
40
45
|
} catch (err) {
|
|
41
|
-
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (process.env.DEBUG?.startsWith("tamagui")) {
|
|
45
|
-
console.log(prefix, `withTamagui skipping resolving ${out}`, err);
|
|
46
|
-
}
|
|
46
|
+
console.log(prefix, `withTamagui skipping resolving ${out}`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
return res;
|
|
49
|
+
return Object.fromEntries(res);
|
|
50
50
|
};
|
|
51
|
-
const resolveEsm = (relativePath, onlyRequire = false) => {
|
|
52
|
-
if (isServer || onlyRequire) {
|
|
53
|
-
return require.resolve(relativePath);
|
|
54
|
-
}
|
|
55
|
-
const esm = resolver(relativePath);
|
|
56
|
-
return esm ? path.join(dir, esm) : require.resolve(relativePath);
|
|
57
|
-
};
|
|
58
|
-
const SEP = path.sep;
|
|
59
|
-
const componentsFullPaths = safeResolves(
|
|
60
|
-
tamaguiOptions.components.map(
|
|
61
|
-
(moduleName) => [moduleName, moduleName]
|
|
62
|
-
),
|
|
63
|
-
true
|
|
64
|
-
);
|
|
65
|
-
const componentsBaseDirs = componentsFullPaths.map(([_, fullPath]) => {
|
|
66
|
-
let rootPath = dirname(fullPath);
|
|
67
|
-
while (rootPath.length > 1) {
|
|
68
|
-
const pkg = join(rootPath, "package.json");
|
|
69
|
-
const hasPkg = existsSync(pkg);
|
|
70
|
-
if (hasPkg) {
|
|
71
|
-
return rootPath;
|
|
72
|
-
} else {
|
|
73
|
-
rootPath = join(rootPath, "..");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
77
|
-
});
|
|
78
|
-
function isInComponentModule(fullPath) {
|
|
79
|
-
return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir));
|
|
80
|
-
}
|
|
81
|
-
const shouldExclude = (path2, projectRoot) => {
|
|
82
|
-
const res = tamaguiOptions.shouldExtract?.(path2, projectRoot);
|
|
83
|
-
if (typeof res === "boolean") {
|
|
84
|
-
return !res;
|
|
85
|
-
}
|
|
86
|
-
if (isInComponentModule(path2)) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
return shouldExcludeDefault(path2, projectRoot);
|
|
90
|
-
};
|
|
91
|
-
const rnw = tamaguiOptions.useReactNativeWebLite ? "react-native-web-lite" : "react-native-web";
|
|
92
|
-
const tamaguiAliases = Object.fromEntries(
|
|
93
|
-
safeResolves([
|
|
94
|
-
["@tamagui/core/reset.css", "@tamagui/core/reset.css"],
|
|
95
|
-
["@tamagui/core", "@tamagui/core"],
|
|
96
|
-
["react-native-svg", "@tamagui/react-native-svg"],
|
|
97
|
-
["react/jsx-runtime.js", "react/jsx-runtime"],
|
|
98
|
-
["react/jsx-runtime", "react/jsx-runtime"],
|
|
99
|
-
["react/jsx-dev-runtime.js", "react/jsx-dev-runtime"],
|
|
100
|
-
["react/jsx-dev-runtime", "react/jsx-dev-runtime"],
|
|
101
|
-
["react-native-reanimated", "react-native-reanimated"],
|
|
102
|
-
["react-native$", rnw],
|
|
103
|
-
["react-native-web$", rnw],
|
|
104
|
-
["@testing-library/react-native", "@tamagui/proxy-worm"],
|
|
105
|
-
["@gorhom/bottom-sheet$", "@gorhom/bottom-sheet"],
|
|
106
|
-
["react-native/Libraries/Renderer/shims/ReactFabric", "@tamagui/proxy-worm"],
|
|
107
|
-
...tamaguiOptions.aliasReactPackages ? [
|
|
108
|
-
["react", "react"],
|
|
109
|
-
["react-dom", "react-dom"]
|
|
110
|
-
] : []
|
|
111
|
-
])
|
|
112
|
-
);
|
|
113
51
|
const alias = {
|
|
114
52
|
...webpackConfig.resolve.alias || {},
|
|
115
|
-
...
|
|
53
|
+
...safeResolves(["react-native-svg", "react-native-svg-web"], ["react/jsx-runtime.js", "react/jsx-runtime"], ["react/jsx-runtime", "react/jsx-runtime"], ["react/jsx-dev-runtime.js", "react/jsx-dev-runtime"], ["react/jsx-dev-runtime", "react/jsx-dev-runtime"], ["react-native-reanimated", "react-native-reanimated"], ["expo-linear-gradient", "@tamagui/expo-linear-gradient"], ["@tamagui/rnw", "@tamagui/rnw"], ["react-native$", "react-native-web"], ["react-native-web$", "react-native-web"], ["@testing-library/react-native", "@tamagui/proxy-worm"], ["@gorhom/bottom-sheet$", "@gorhom/bottom-sheet"], ["react-native/Libraries/Renderer/shims/ReactFabric", "@tamagui/proxy-worm"], ...tamaguiOptions.aliasReactPackages ? [
|
|
54
|
+
["react", "react"],
|
|
55
|
+
["react-dom", "react-dom"]
|
|
56
|
+
] : [])
|
|
116
57
|
};
|
|
117
58
|
if (process.env.DEBUG) {
|
|
118
59
|
console.log("Tamagui alias:", alias);
|
|
119
60
|
}
|
|
120
|
-
if (process.env.ANALYZE === "true") {
|
|
121
|
-
Object.assign(webpackConfig.optimization, {
|
|
122
|
-
concatenateModules: false
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
61
|
webpackConfig.resolve.alias = alias;
|
|
126
|
-
webpackConfig.plugins.push(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})
|
|
132
|
-
);
|
|
62
|
+
webpackConfig.plugins.push(new webpack.DefinePlugin({
|
|
63
|
+
"process.env.IS_STATIC": '""',
|
|
64
|
+
"process.env.TAMAGUI_TARGET": '"web"',
|
|
65
|
+
__DEV__: JSON.stringify(dev)
|
|
66
|
+
}));
|
|
133
67
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports;
|
|
134
68
|
if (Array.isArray(excludeExports)) {
|
|
69
|
+
if (excludeExports.includes("PressResponder")) {
|
|
70
|
+
console.warn(`\u26A0\uFE0F Warning: as of beta 118, PressReponder shouldn't be excluded in excludeReactNativeWebExports`);
|
|
71
|
+
}
|
|
135
72
|
try {
|
|
136
|
-
const regexStr = `react-native-web(
|
|
73
|
+
const regexStr = `react-native-web/.*(${excludeExports.join("|")}).*js`;
|
|
137
74
|
const regex = new RegExp(regexStr);
|
|
138
|
-
webpackConfig.plugins.push(
|
|
139
|
-
new webpack.NormalModuleReplacementPlugin(regex, resolveEsm("@tamagui/proxy-worm"))
|
|
140
|
-
);
|
|
75
|
+
webpackConfig.plugins.push(new webpack.NormalModuleReplacementPlugin(regex, resolveEsm("@tamagui/proxy-worm/empty-react-native-view")));
|
|
141
76
|
} catch (err) {
|
|
142
|
-
console.warn(
|
|
143
|
-
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(", ")}`
|
|
144
|
-
);
|
|
77
|
+
console.warn(`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(", ")}`);
|
|
145
78
|
}
|
|
146
79
|
}
|
|
147
80
|
if (process.env.IGNORE_TS_CONFIG_PATHS) {
|
|
@@ -153,18 +86,17 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
153
86
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
154
87
|
}
|
|
155
88
|
}
|
|
156
|
-
if (!dev
|
|
157
|
-
const cssMin = webpackConfig.optimization.minimizer.find(
|
|
158
|
-
(x) => x.toString().includes("css-minimizer-plugin")
|
|
159
|
-
);
|
|
89
|
+
if (!dev) {
|
|
90
|
+
const cssMin = webpackConfig.optimization.minimizer.find((x) => x.toString().includes("css-minimizer-plugin"));
|
|
160
91
|
if (cssMin) {
|
|
161
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
162
|
-
cssMin.index,
|
|
163
|
-
1
|
|
164
|
-
);
|
|
92
|
+
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(cssMin.index, 1);
|
|
165
93
|
}
|
|
166
94
|
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin());
|
|
167
95
|
}
|
|
96
|
+
webpackConfig.resolve.extensions = [
|
|
97
|
+
.../* @__PURE__ */ new Set([".web.tsx", ".web.ts", ".web.js", ...webpackConfig.resolve.extensions])
|
|
98
|
+
];
|
|
99
|
+
webpackConfig.resolve.mainFields.unshift("module:jsx");
|
|
168
100
|
if (isServer) {
|
|
169
101
|
const externalize = (context, request) => {
|
|
170
102
|
const fullPath = request[0] === "." ? path.join(context, request) : request;
|
|
@@ -178,22 +110,16 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
178
110
|
return userRes;
|
|
179
111
|
}
|
|
180
112
|
}
|
|
181
|
-
if (
|
|
113
|
+
if (fullPath === "react-native" || fullPath.startsWith("react-native/")) {
|
|
182
114
|
return false;
|
|
183
115
|
}
|
|
184
|
-
if (fullPath.includes("react-native-web
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if (fullPath === "react-native" || fullPath.startsWith(`react-native${SEP}`)) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
if (fullPath.startsWith("react-native-web") || fullPath.includes(`node_modules${SEP}react-native-web`) || new RegExp(`^(react-dom|react)${SEP}$`).test(fullPath)) {
|
|
116
|
+
if (fullPath.startsWith("react-native-web") || fullPath.includes("node_modules/react-native-web") || /^(react-dom|react)\/$/.test(fullPath)) {
|
|
191
117
|
return `commonjs ${fullPath}`;
|
|
192
118
|
}
|
|
193
|
-
if (fullPath.
|
|
119
|
+
if (fullPath.includes("/moti/") || fullPath.includes("/solito/") || fullPath === "tamagui" || fullPath.startsWith("@tamagui/") || fullPath === "react-native-safe-area-context" || fullPath.startsWith("@react-navigation") || fullPath === "@gorhom/bottom-sheet") {
|
|
194
120
|
return;
|
|
195
121
|
}
|
|
196
|
-
if (
|
|
122
|
+
if (/^\@?react-native-/.test(request)) {
|
|
197
123
|
return false;
|
|
198
124
|
}
|
|
199
125
|
return true;
|
|
@@ -220,81 +146,115 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
220
146
|
})
|
|
221
147
|
];
|
|
222
148
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
149
|
+
const oneOfRule = webpackConfig.module.rules.find((x) => !!x.oneOf);
|
|
150
|
+
const cssLoader = getGlobalCssLoader({
|
|
151
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
152
|
+
future: nextConfig.future,
|
|
153
|
+
experimental: nextConfig.experimental || {},
|
|
154
|
+
isClient: !isServer,
|
|
155
|
+
isServer,
|
|
156
|
+
isDevelopment: dev
|
|
157
|
+
}, () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)), []);
|
|
158
|
+
if (oneOfRule) {
|
|
229
159
|
if (!tamaguiOptions.disableFontSupport) {
|
|
230
|
-
|
|
160
|
+
oneOfRule.oneOf.unshift({
|
|
231
161
|
test: /\.(woff(2)?|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
|
|
232
162
|
use: [
|
|
233
163
|
{
|
|
234
164
|
loader: require.resolve("url-loader"),
|
|
235
165
|
options: {
|
|
236
|
-
limit: nextConfig.inlineFontLimit ||
|
|
166
|
+
limit: nextConfig.inlineFontLimit || 8192,
|
|
237
167
|
fallback: require.resolve("file-loader"),
|
|
238
168
|
publicPath: `${nextConfig.assetPrefix || ""}/_next/static/chunks/fonts/`,
|
|
239
169
|
outputPath: `${isServer ? "../" : ""}static/chunks/fonts/`,
|
|
240
|
-
name: "[name].[ext]"
|
|
170
|
+
name: "[name]-[hash].[ext]"
|
|
241
171
|
}
|
|
242
172
|
}
|
|
243
173
|
]
|
|
244
174
|
});
|
|
245
175
|
}
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
experimental: nextConfig.experimental || {},
|
|
251
|
-
isEdgeRuntime: true,
|
|
252
|
-
isProduction: !dev,
|
|
253
|
-
targetWeb: true,
|
|
254
|
-
isClient: !isServer,
|
|
255
|
-
isServer,
|
|
256
|
-
isDevelopment: dev
|
|
257
|
-
},
|
|
258
|
-
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
259
|
-
[]
|
|
260
|
-
);
|
|
261
|
-
const cssTest = tamaguiOptions.includeCSSTest ?? /\.css$/;
|
|
262
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
176
|
+
const cssTest = (_b = tamaguiOptions.includeCSSTest) != null ? _b : (file) => {
|
|
177
|
+
return file.endsWith(".module.css");
|
|
178
|
+
};
|
|
179
|
+
if (!dev) {
|
|
263
180
|
const postCSSLoader = cssLoader[cssLoader.length - 1];
|
|
264
|
-
|
|
181
|
+
oneOfRule.oneOf.unshift({
|
|
265
182
|
test: cssTest,
|
|
266
183
|
use: [MiniCSSExtractPlugin.loader, "css-loader", postCSSLoader],
|
|
267
184
|
sideEffects: true
|
|
268
185
|
});
|
|
269
|
-
webpackConfig.plugins.push(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
)
|
|
186
|
+
webpackConfig.plugins.push(new MiniCSSExtractPlugin({
|
|
187
|
+
filename: "static/css/[name].[contenthash].css",
|
|
188
|
+
ignoreOrder: true,
|
|
189
|
+
runtime: false
|
|
190
|
+
}));
|
|
191
|
+
if (tamaguiOptions.inlineCSS) {
|
|
192
|
+
webpackConfig.plugins.push(new InlineCSSPlugin());
|
|
193
|
+
}
|
|
275
194
|
} else {
|
|
276
|
-
|
|
195
|
+
oneOfRule.oneOf.unshift({
|
|
277
196
|
test: cssTest,
|
|
278
197
|
sideEffects: true,
|
|
279
198
|
use: cssLoader
|
|
280
199
|
});
|
|
281
200
|
}
|
|
282
|
-
cssRules.unshift({
|
|
283
|
-
test: cssTest,
|
|
284
|
-
sideEffects: true,
|
|
285
|
-
use: cssLoader
|
|
286
|
-
});
|
|
287
201
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
202
|
+
if (isNext12) {
|
|
203
|
+
const firstOneOfRule = webpackConfig.module.rules.findIndex((x) => x && !!x.oneOf);
|
|
204
|
+
const oneOfJSRules = webpackConfig.module.rules[firstOneOfRule].oneOf;
|
|
205
|
+
const afterSWCLoaderIndex = oneOfJSRules.findIndex((x) => x && x.use && x.use.loader === "next-swc-loader" && x.issuerLayer !== "api") + 1;
|
|
206
|
+
const swcLoader = oneOfJSRules[afterSWCLoaderIndex];
|
|
207
|
+
oneOfJSRules.splice(afterSWCLoaderIndex, 0, {
|
|
208
|
+
test: /(bottom-sheet).*\.[tj]sx?$/,
|
|
209
|
+
use: [
|
|
210
|
+
{
|
|
211
|
+
loader: "babel-loader",
|
|
212
|
+
options: {
|
|
213
|
+
presets: ["@babel/preset-react"],
|
|
214
|
+
plugins: ["react-native-reanimated/plugin"]
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}, {
|
|
219
|
+
test: /\.(jsx?|tsx?)$/,
|
|
220
|
+
exclude: (path2) => shouldExclude(path2, options.dir),
|
|
221
|
+
use: [
|
|
222
|
+
...[].concat(swcLoader.use),
|
|
223
|
+
{
|
|
224
|
+
loader: "tamagui-loader",
|
|
225
|
+
options: tamaguiOptions
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
const [first, second, ...rest] = webpackConfig.module.rules;
|
|
231
|
+
webpackConfig.module.rules = [
|
|
232
|
+
first,
|
|
233
|
+
second,
|
|
234
|
+
{
|
|
235
|
+
test: /\.(tsx|jsx)$/,
|
|
236
|
+
exclude: (path2) => shouldExclude(path2, options.dir),
|
|
237
|
+
use: [
|
|
238
|
+
"thread-loader",
|
|
239
|
+
{
|
|
240
|
+
loader: "esbuild-loader",
|
|
241
|
+
options: {
|
|
242
|
+
loader: "tsx",
|
|
243
|
+
minify: false
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
loader: "tamagui-loader",
|
|
248
|
+
options: {
|
|
249
|
+
prefixLogs: prefix,
|
|
250
|
+
...tamaguiOptions
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
]
|
|
294
254
|
},
|
|
295
|
-
...
|
|
296
|
-
|
|
297
|
-
|
|
255
|
+
...rest
|
|
256
|
+
];
|
|
257
|
+
}
|
|
298
258
|
if (typeof nextConfig.webpack === "function") {
|
|
299
259
|
return nextConfig.webpack(webpackConfig, options);
|
|
300
260
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/withTamagui.ts"],
|
|
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 CssMinimizerPlugin from 'css-minimizer-webpack-plugin'\nimport buildResolver from 'esm-resolve'\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 { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n enableCSSOptimizations?: 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][], multiple = false) => {\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 if (multiple) {\n res.push([out, resolveEsm(mod, true)])\n }\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 res\n }\n\n const resolveEsm = (relativePath: string, onlyRequire = false) => {\n if (isServer || onlyRequire) {\n return require.resolve(relativePath)\n }\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 true\n )\n\n const componentsBaseDirs = componentsFullPaths.map(([_, 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 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 = Object.fromEntries(\n 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\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 (!dev && tamaguiOptions.enableCSSOptimizations) {\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 /**\n * Server react-native compat\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 /**\n * Font Support\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 /**\n * CSS Support\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 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 const cssTest = tamaguiOptions.includeCSSTest ?? /\\.css$/\n\n if (!dev && tamaguiOptions.enableCSSOptimizations) {\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 } else {\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n cssRules.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\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
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import path, { 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 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 // 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 return shouldExcludeDefault(path, projectRoot)\n }\n\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 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 // @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 const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n console.log(prefix, `withTamagui skipping resolving ${out}`)\n }\n }\n return Object.fromEntries(res)\n }\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...safeResolves(\n ['react-native-svg', 'react-native-svg-web'],\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 ['expo-linear-gradient', '@tamagui/expo-linear-gradient'],\n // match commonjs to react-native-web\n // i'd do esm but needs better docs, have to transpile\n ['@tamagui/rnw', '@tamagui/rnw'],\n ['react-native$', 'react-native-web'],\n ['react-native-web$', 'react-native-web'],\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\n if (process.env.DEBUG) {\n console.log('Tamagui alias:', alias)\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/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(\n regex,\n resolveEsm('@tamagui/proxy-worm/empty-react-native-view')\n )\n )\n } catch (err) {\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 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 // must inline react-native so we can alias to react-native-web\n if (fullPath === 'react-native' || fullPath.startsWith('react-native/')) {\n return false\n }\n\n if (\n // feather icons uses react-native-svg which needs to be aliased\n // fullPath.includes('/feather-icons/') ||\n fullPath.startsWith('react-native-web') ||\n fullPath.includes('node_modules/react-native-web') ||\n /^(react-dom|react)\\/$/.test(fullPath)\n ) {\n return `commonjs ${fullPath}`\n }\n if (\n fullPath.includes('/moti/') ||\n fullPath.includes('/solito/') ||\n fullPath === 'tamagui' ||\n fullPath.startsWith('@tamagui/') ||\n fullPath === 'react-native-safe-area-context' ||\n fullPath.startsWith('@react-navigation') ||\n fullPath === '@gorhom/bottom-sheet'\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 oneOfRule = webpackConfig.module.rules.find((x) => !!x.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 (oneOfRule) {\n if (!tamaguiOptions.disableFontSupport) {\n // fonts support\n oneOfRule.oneOf.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 || 8192,\n fallback: require.resolve('file-loader'),\n publicPath: `${nextConfig.assetPrefix || ''}/_next/static/chunks/fonts/`,\n outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,\n name: '[name]-[hash].[ext]',\n },\n },\n ],\n })\n }\n\n const cssTest =\n tamaguiOptions.includeCSSTest ??\n ((file) => {\n return file.endsWith('.module.css')\n })\n\n if (!dev) {\n const postCSSLoader = cssLoader[cssLoader.length - 1]\n // replace nextjs picky style rules with simple minicssextract\n oneOfRule.oneOf.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/[name].[contenthash].css',\n ignoreOrder: true,\n runtime: false,\n })\n )\n if (tamaguiOptions.inlineCSS) {\n webpackConfig.plugins.push(new InlineCSSPlugin())\n }\n } else {\n oneOfRule.oneOf.unshift({\n test: cssTest,\n sideEffects: true,\n use: cssLoader,\n })\n }\n }\n\n if (isNext12) {\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).*\\.[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 } else {\n // next 11 modify loader\n const [first, second, ...rest] = webpackConfig.module.rules\n webpackConfig.module.rules = [\n first,\n second,\n {\n test: /\\.(tsx|jsx)$/,\n exclude: (path: string) => shouldExclude(path, options.dir),\n use: [\n 'thread-loader',\n {\n loader: 'esbuild-loader',\n options: {\n loader: 'tsx',\n minify: false,\n },\n },\n {\n loader: 'tamagui-loader',\n options: {\n prefixLogs: prefix,\n ...tamaguiOptions,\n },\n },\n ],\n },\n ...rest,\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;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeO,MAAM,cAAc,CAAC,mBAAqC;AAE/D,QAAM,gBAAgB,CAAC,OAAc,gBAAwB;AA5B/D;AA6BI,UAAM,MAAM,qBAAe,kBAAf,wCAA+B,OAAM;AACjD,QAAI,OAAO,QAAQ,WAAW;AAC5B,aAAO,CAAC;AAAA,IACV;AACA,WAAO,qBAAqB,OAAM,WAAW;AAAA,EAC/C;AAEA,SAAO,CAAC,aAAkB,CAAC,MAAM;AAC/B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,CAAC,eAAoB,YAAiB;AAvCrD;AAwCQ,cAAM,EAAE,KAAK,QAAQ,KAAK,aAAa;AAEvC,cAAM,WAAW,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D,wBAAc,OAAO,QAAQ;AAAA,YAC3B;AAAA,YACA;AAAA,YACA;AAAA,cACE,MAAM;AAAA,cACN,SAAS,CAAC,UAAiB,cAAc,OAAM,QAAQ,GAAG;AAAA,cAC1D,KAAK;AAAA,gBACH;AAAA,gBACA;AAAA,kBACE,QAAQ;AAAA,kBACR,SAAS;AAAA,oBACP,QAAQ;AAAA,oBACR,QAAQ;AAAA,kBACV;AAAA,gBACF;AAAA,gBACA;AAAA,kBACE,QAAQ;AAAA,kBACR,SAAS;AAAA,oBACP,YAAY;AAAA,oBACZ,GAAG;AAAA,kBACL;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,YACA,GAAG;AAAA,UACL;AAAA,QACF;AAEA,YAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,iBAAO,WAAW,QAAQ,eAAe,OAAO;AAAA,QAClD;AAEA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEA,8BAA8B,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,EAAO;AAET,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/next-plugin",
|
|
3
|
-
"version": "1.0.1-rc.
|
|
3
|
+
"version": "1.0.1-rc.10",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -14,32 +14,29 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tamagui-build",
|
|
16
16
|
"watch": "tamagui-build --watch",
|
|
17
|
-
"lint": "
|
|
18
|
-
"lint:fix": "
|
|
17
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
18
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src",
|
|
19
19
|
"clean": "tamagui-build clean",
|
|
20
20
|
"clean:build": "tamagui-build clean:build"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/preset-react": "^7.18.6",
|
|
24
|
-
"@tamagui/proxy-worm": "^1.0.1-rc.
|
|
25
|
-
"@tamagui/react-native-svg": "^1.0.1-rc.
|
|
26
|
-
"@tamagui/static": "^1.0.1-rc.
|
|
24
|
+
"@tamagui/proxy-worm": "^1.0.1-rc.10",
|
|
25
|
+
"@tamagui/react-native-svg": "^1.0.1-rc.10",
|
|
26
|
+
"@tamagui/static": "^1.0.1-rc.10",
|
|
27
27
|
"babel-loader": "^8.2.5",
|
|
28
28
|
"browserslist": "^4.21.1",
|
|
29
29
|
"css-loader": "^5.2.4",
|
|
30
|
-
"css-minimizer-webpack-plugin": "^4.2.2",
|
|
31
30
|
"esbuild-loader": "^2.19.0",
|
|
32
31
|
"esm-resolve": "^1.0.8",
|
|
33
32
|
"file-loader": "^6.2.0",
|
|
34
|
-
"html-inline-css-webpack-plugin": "^1.11.1",
|
|
35
33
|
"html-webpack-plugin": "^5.5.0",
|
|
36
|
-
"
|
|
37
|
-
"tamagui-loader": "^1.0.1-rc.1.4",
|
|
34
|
+
"tamagui-loader": "^1.0.1-rc.10",
|
|
38
35
|
"thread-loader": "^3.0.4",
|
|
39
36
|
"url-loader": "^4.1.1"
|
|
40
37
|
},
|
|
41
38
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "^1.0.1-rc.
|
|
39
|
+
"@tamagui/build": "^1.0.1-rc.10",
|
|
43
40
|
"next": "^13.0.6"
|
|
44
41
|
},
|
|
45
42
|
"peerDependencies": {
|
package/src/withTamagui.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } 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 MiniCSSExtractPlugin from 'mini-css-extract-plugin'
|
|
9
7
|
import { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'
|
|
10
8
|
import { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'
|
|
11
9
|
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'
|
|
@@ -14,7 +12,6 @@ import webpack from 'webpack'
|
|
|
14
12
|
export type WithTamaguiProps = TamaguiOptions & {
|
|
15
13
|
useReactNativeWebLite: boolean
|
|
16
14
|
disableFontSupport?: boolean
|
|
17
|
-
enableCSSOptimizations?: boolean
|
|
18
15
|
aliasReactPackages?: boolean
|
|
19
16
|
includeCSSTest?: RegExp | ((path: string) => boolean)
|
|
20
17
|
shouldExtract?: (path: string, projectRoot: string) => boolean | undefined
|
|
@@ -107,7 +104,9 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
107
104
|
})
|
|
108
105
|
|
|
109
106
|
function isInComponentModule(fullPath: string) {
|
|
110
|
-
return componentsBaseDirs.some((componentDir) =>
|
|
107
|
+
return componentsBaseDirs.some((componentDir) =>
|
|
108
|
+
fullPath.startsWith(componentDir)
|
|
109
|
+
)
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
// allows configuration
|
|
@@ -130,6 +129,7 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
130
129
|
safeResolves([
|
|
131
130
|
['@tamagui/core/reset.css', '@tamagui/core/reset.css'],
|
|
132
131
|
['@tamagui/core', '@tamagui/core'],
|
|
132
|
+
// web specific light react-native-svg, optional, can use svgs but had issues with compat
|
|
133
133
|
['react-native-svg', '@tamagui/react-native-svg'],
|
|
134
134
|
// fixes https://github.com/kentcdodds/mdx-bundler/issues/143
|
|
135
135
|
['react/jsx-runtime.js', 'react/jsx-runtime'],
|
|
@@ -181,16 +181,23 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
181
181
|
const excludeExports = tamaguiOptions.excludeReactNativeWebExports
|
|
182
182
|
if (Array.isArray(excludeExports)) {
|
|
183
183
|
try {
|
|
184
|
-
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join(
|
|
184
|
+
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join(
|
|
185
|
+
'|'
|
|
186
|
+
)}).*js`
|
|
185
187
|
const regex = new RegExp(regexStr)
|
|
186
188
|
// console.log(prefix, 'exclude', regexStr)
|
|
187
189
|
webpackConfig.plugins.push(
|
|
188
|
-
new webpack.NormalModuleReplacementPlugin(
|
|
190
|
+
new webpack.NormalModuleReplacementPlugin(
|
|
191
|
+
regex,
|
|
192
|
+
resolveEsm('@tamagui/proxy-worm')
|
|
193
|
+
)
|
|
189
194
|
)
|
|
190
195
|
} catch (err) {
|
|
191
196
|
// eslint-disable-next-line no-console
|
|
192
197
|
console.warn(
|
|
193
|
-
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(
|
|
198
|
+
`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(
|
|
199
|
+
', '
|
|
200
|
+
)}`
|
|
194
201
|
)
|
|
195
202
|
}
|
|
196
203
|
}
|
|
@@ -206,19 +213,6 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
206
213
|
}
|
|
207
214
|
}
|
|
208
215
|
|
|
209
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
210
|
-
const cssMin = webpackConfig.optimization.minimizer.find((x) =>
|
|
211
|
-
x.toString().includes('css-minimizer-plugin')
|
|
212
|
-
)
|
|
213
|
-
if (cssMin) {
|
|
214
|
-
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.slice(
|
|
215
|
-
cssMin.index,
|
|
216
|
-
1
|
|
217
|
-
)
|
|
218
|
-
}
|
|
219
|
-
webpackConfig.optimization.minimizer.push(new CssMinimizerPlugin())
|
|
220
|
-
}
|
|
221
|
-
|
|
222
216
|
/**
|
|
223
217
|
* Server react-native compat
|
|
224
218
|
*/
|
|
@@ -247,7 +241,10 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
247
241
|
}
|
|
248
242
|
|
|
249
243
|
// must inline react-native so we can alias to react-native-web
|
|
250
|
-
if (
|
|
244
|
+
if (
|
|
245
|
+
fullPath === 'react-native' ||
|
|
246
|
+
fullPath.startsWith(`react-native${SEP}`)
|
|
247
|
+
) {
|
|
251
248
|
return false
|
|
252
249
|
}
|
|
253
250
|
|
|
@@ -307,6 +304,9 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
307
304
|
]
|
|
308
305
|
}
|
|
309
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Non-server support
|
|
309
|
+
*/
|
|
310
310
|
const cssRules = webpackConfig.module.rules.find(
|
|
311
311
|
(rule) =>
|
|
312
312
|
Array.isArray(rule.oneOf) &&
|
|
@@ -332,7 +332,9 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
332
332
|
options: {
|
|
333
333
|
limit: nextConfig.inlineFontLimit || 1024,
|
|
334
334
|
fallback: require.resolve('file-loader'),
|
|
335
|
-
publicPath: `${
|
|
335
|
+
publicPath: `${
|
|
336
|
+
nextConfig.assetPrefix || ''
|
|
337
|
+
}/_next/static/chunks/fonts/`,
|
|
336
338
|
outputPath: `${isServer ? '../' : ''}static/chunks/fonts/`,
|
|
337
339
|
name: '[name].[ext]',
|
|
338
340
|
},
|
|
@@ -362,31 +364,8 @@ export const withTamagui = (tamaguiOptions: WithTamaguiProps) => {
|
|
|
362
364
|
[]
|
|
363
365
|
)
|
|
364
366
|
|
|
365
|
-
const cssTest = tamaguiOptions.includeCSSTest ?? /\.tamagui\.css$/
|
|
366
|
-
|
|
367
|
-
if (!dev && tamaguiOptions.enableCSSOptimizations) {
|
|
368
|
-
const postCSSLoader = cssLoader[cssLoader.length - 1]
|
|
369
|
-
// replace nextjs picky style rules with simple minicssextract
|
|
370
|
-
cssRules.unshift({
|
|
371
|
-
test: cssTest,
|
|
372
|
-
use: [MiniCSSExtractPlugin.loader, 'css-loader', postCSSLoader],
|
|
373
|
-
sideEffects: true,
|
|
374
|
-
})
|
|
375
|
-
webpackConfig.plugins.push(
|
|
376
|
-
new MiniCSSExtractPlugin({
|
|
377
|
-
filename: 'static/css/[contenthash].css',
|
|
378
|
-
ignoreOrder: true,
|
|
379
|
-
})
|
|
380
|
-
)
|
|
381
|
-
} else {
|
|
382
|
-
cssRules.unshift({
|
|
383
|
-
test: cssTest,
|
|
384
|
-
sideEffects: true,
|
|
385
|
-
use: cssLoader,
|
|
386
|
-
})
|
|
387
|
-
}
|
|
388
367
|
cssRules.unshift({
|
|
389
|
-
test:
|
|
368
|
+
test: tamaguiOptions.includeCSSTest ?? /\.tamagui\.css$/,
|
|
390
369
|
sideEffects: true,
|
|
391
370
|
use: cssLoader,
|
|
392
371
|
})
|
package/types/withTamagui.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { TamaguiOptions } from '@tamagui/static';
|
|
|
2
2
|
export type WithTamaguiProps = TamaguiOptions & {
|
|
3
3
|
useReactNativeWebLite: boolean;
|
|
4
4
|
disableFontSupport?: boolean;
|
|
5
|
-
enableCSSOptimizations?: boolean;
|
|
6
5
|
aliasReactPackages?: boolean;
|
|
7
6
|
includeCSSTest?: RegExp | ((path: string) => boolean);
|
|
8
7
|
shouldExtract?: (path: string, projectRoot: string) => boolean | undefined;
|