@tamagui/next-plugin 1.0.1-beta.226 → 1.0.1-beta.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/withTamagui.js +94 -53
- package/dist/cjs/withTamagui.js.map +3 -3
- package/dist/esm/withTamagui.js +94 -53
- package/dist/esm/withTamagui.js.map +2 -2
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/withTamagui.js +320 -0
- package/dist/jsx/withTamagui.js.map +7 -0
- package/package.json +8 -6
- package/src/withTamagui.ts +106 -59
- package/types/withTamagui.d.ts +1 -0
package/dist/cjs/withTamagui.js
CHANGED
|
@@ -30,7 +30,9 @@ 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"));
|
|
33
34
|
var import_esm_resolve = __toESM(require("esm-resolve"));
|
|
35
|
+
var import_mini_css_extract_plugin = __toESM(require("mini-css-extract-plugin"));
|
|
34
36
|
var import_css = require("next/dist/build/webpack/config/blocks/css");
|
|
35
37
|
var import_loaders = require("next/dist/build/webpack/config/blocks/css/loaders");
|
|
36
38
|
var import_tamagui_loader = require("tamagui-loader");
|
|
@@ -53,7 +55,7 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
53
55
|
throw new Error(`Next.js 12 only supported`);
|
|
54
56
|
}
|
|
55
57
|
const prefix = `${isServer ? " ssr " : " web "} |`;
|
|
56
|
-
const safeResolves = (
|
|
58
|
+
const safeResolves = (resolves, multiple = false) => {
|
|
57
59
|
var _a2;
|
|
58
60
|
const res = [];
|
|
59
61
|
for (const [out, mod] of resolves) {
|
|
@@ -63,6 +65,9 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
63
65
|
}
|
|
64
66
|
try {
|
|
65
67
|
res.push([out, resolveEsm(mod)]);
|
|
68
|
+
if (multiple) {
|
|
69
|
+
res.push([out, resolveEsm(mod, true)]);
|
|
70
|
+
}
|
|
66
71
|
} catch (err) {
|
|
67
72
|
if (out.includes(`@gorhom/bottom-sheet`)) {
|
|
68
73
|
continue;
|
|
@@ -72,35 +77,35 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
return
|
|
80
|
+
return res;
|
|
76
81
|
};
|
|
77
|
-
const resolveEsm = (relativePath) => {
|
|
78
|
-
if (isServer)
|
|
82
|
+
const resolveEsm = (relativePath, onlyRequire = false) => {
|
|
83
|
+
if (isServer || onlyRequire) {
|
|
79
84
|
return require.resolve(relativePath);
|
|
85
|
+
}
|
|
80
86
|
const esm = resolver(relativePath);
|
|
81
87
|
return esm ? import_path.default.join(dir, esm) : require.resolve(relativePath);
|
|
82
88
|
};
|
|
83
89
|
const SEP = import_path.default.sep;
|
|
84
90
|
const componentsFullPaths = safeResolves(
|
|
85
|
-
|
|
91
|
+
tamaguiOptions.components.map(
|
|
86
92
|
(moduleName) => [moduleName, moduleName]
|
|
87
|
-
)
|
|
93
|
+
),
|
|
94
|
+
true
|
|
88
95
|
);
|
|
89
|
-
const componentsBaseDirs =
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
rootPath = (0, import_path.join)(rootPath, "..");
|
|
99
|
-
}
|
|
96
|
+
const componentsBaseDirs = componentsFullPaths.map(([_, fullPath]) => {
|
|
97
|
+
let rootPath = (0, import_path.dirname)(fullPath);
|
|
98
|
+
while (rootPath.length > 1) {
|
|
99
|
+
const pkg = (0, import_path.join)(rootPath, "package.json");
|
|
100
|
+
const hasPkg = (0, import_fs.existsSync)(pkg);
|
|
101
|
+
if (hasPkg) {
|
|
102
|
+
return rootPath;
|
|
103
|
+
} else {
|
|
104
|
+
rootPath = (0, import_path.join)(rootPath, "..");
|
|
100
105
|
}
|
|
101
|
-
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
102
106
|
}
|
|
103
|
-
|
|
107
|
+
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
108
|
+
});
|
|
104
109
|
function isInComponentModule(fullPath) {
|
|
105
110
|
return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir));
|
|
106
111
|
}
|
|
@@ -116,24 +121,26 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
116
121
|
return (0, import_tamagui_loader.shouldExclude)(path2, projectRoot);
|
|
117
122
|
};
|
|
118
123
|
const rnw = tamaguiOptions.useReactNativeWebLite ? "react-native-web-lite" : "react-native-web";
|
|
119
|
-
const tamaguiAliases =
|
|
120
|
-
[
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
[
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
const tamaguiAliases = Object.fromEntries(
|
|
125
|
+
safeResolves([
|
|
126
|
+
["@tamagui/core/reset.css", "@tamagui/core/reset.css"],
|
|
127
|
+
["@tamagui/core", "@tamagui/core"],
|
|
128
|
+
["react-native-svg", "@tamagui/react-native-svg"],
|
|
129
|
+
["react/jsx-runtime.js", "react/jsx-runtime"],
|
|
130
|
+
["react/jsx-runtime", "react/jsx-runtime"],
|
|
131
|
+
["react/jsx-dev-runtime.js", "react/jsx-dev-runtime"],
|
|
132
|
+
["react/jsx-dev-runtime", "react/jsx-dev-runtime"],
|
|
133
|
+
["react-native-reanimated", "react-native-reanimated"],
|
|
134
|
+
["react-native$", rnw],
|
|
135
|
+
["react-native-web$", rnw],
|
|
136
|
+
["@testing-library/react-native", "@tamagui/proxy-worm"],
|
|
137
|
+
["@gorhom/bottom-sheet$", "@gorhom/bottom-sheet"],
|
|
138
|
+
["react-native/Libraries/Renderer/shims/ReactFabric", "@tamagui/proxy-worm"],
|
|
139
|
+
...tamaguiOptions.aliasReactPackages ? [
|
|
140
|
+
["react", "react"],
|
|
141
|
+
["react-dom", "react-dom"]
|
|
142
|
+
] : []
|
|
143
|
+
])
|
|
137
144
|
);
|
|
138
145
|
const alias = {
|
|
139
146
|
...webpackConfig.resolve.alias || {},
|
|
@@ -178,6 +185,18 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
178
185
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
179
186
|
}
|
|
180
187
|
}
|
|
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
|
+
}
|
|
181
200
|
if (isServer) {
|
|
182
201
|
const externalize = (context, request) => {
|
|
183
202
|
const fullPath = request[0] === "." ? import_path.default.join(context, request) : request;
|
|
@@ -256,24 +275,46 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
256
275
|
]
|
|
257
276
|
});
|
|
258
277
|
}
|
|
278
|
+
const cssLoader = (0, import_loaders.getGlobalCssLoader)(
|
|
279
|
+
{
|
|
280
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
281
|
+
future: nextConfig.future,
|
|
282
|
+
experimental: nextConfig.experimental || {},
|
|
283
|
+
isEdgeRuntime: true,
|
|
284
|
+
isProduction: !dev,
|
|
285
|
+
targetWeb: true,
|
|
286
|
+
isClient: !isServer,
|
|
287
|
+
isServer,
|
|
288
|
+
isDevelopment: dev
|
|
289
|
+
},
|
|
290
|
+
() => (0, import_css.lazyPostCSS)(dir, getSupportedBrowsers(dir, dev)),
|
|
291
|
+
[]
|
|
292
|
+
);
|
|
293
|
+
const cssTest = tamaguiOptions.includeCSSTest ?? /\.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
|
+
}
|
|
259
314
|
cssRules.unshift({
|
|
260
|
-
test:
|
|
315
|
+
test: cssTest,
|
|
261
316
|
sideEffects: true,
|
|
262
|
-
use:
|
|
263
|
-
{
|
|
264
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
265
|
-
future: nextConfig.future,
|
|
266
|
-
experimental: nextConfig.experimental || {},
|
|
267
|
-
isEdgeRuntime: true,
|
|
268
|
-
isProduction: !dev,
|
|
269
|
-
targetWeb: true,
|
|
270
|
-
isClient: !isServer,
|
|
271
|
-
isServer,
|
|
272
|
-
isDevelopment: dev
|
|
273
|
-
},
|
|
274
|
-
() => (0, import_css.lazyPostCSS)(dir, getSupportedBrowsers(dir, dev)),
|
|
275
|
-
[]
|
|
276
|
-
)
|
|
317
|
+
use: cssLoader
|
|
277
318
|
});
|
|
278
319
|
}
|
|
279
320
|
webpackConfig.plugins.push(
|
|
@@ -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 buildResolver from 'esm-resolve'\nimport { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css'\nimport { getGlobalCssLoader } from 'next/dist/build/webpack/config/blocks/css/loaders'\nimport { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from 'tamagui-loader'\nimport webpack from 'webpack'\n\nexport type WithTamaguiProps = TamaguiOptions & {\n useReactNativeWebLite: boolean\n disableFontSupport?: boolean\n aliasReactPackages?: boolean\n includeCSSTest?: RegExp | ((path: string) => boolean)\n shouldExtract?: (path: string, projectRoot: string) => boolean | undefined\n shouldExcludeFromServer?: (props: {\n context: string\n request: string\n fullPath: string\n }) => boolean | string | undefined\n}\n\nexport const withTamagui = (tamaguiOptions: WithTamaguiProps) => {\n return (nextConfig: any = {}) => {\n return {\n ...nextConfig,\n webpack: (webpackConfig: any, options: any) => {\n const { dir, config, dev, isServer } = options\n\n const resolver = buildResolver(join(dir, 'index.js'), {\n constraints: 'node',\n })\n\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = dev\n }\n\n const isNext12 = typeof options.config?.swcMinify === 'boolean'\n if (!isNext12) {\n throw new Error(`Next.js 12 only supported`)\n }\n\n const prefix = `${isServer ? ' ssr ' : ' web '} |`\n\n const safeResolves = (...resolves: [string, string][]) => {\n const res: string[][] = []\n for (const [out, mod] of resolves) {\n if (out.endsWith('$')) {\n res.push([out, mod])\n continue\n }\n try {\n res.push([out, resolveEsm(mod)])\n } catch (err) {\n if (out.includes(`@gorhom/bottom-sheet`)) {\n continue\n }\n if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(prefix, `withTamagui skipping resolving ${out}`, err)\n }\n }\n }\n return Object.fromEntries(res)\n }\n\n const resolveEsm = (relativePath: string) => {\n if (isServer) return require.resolve(relativePath)\n const esm = resolver(relativePath)\n return esm ? path.join(dir, esm) : require.resolve(relativePath)\n }\n\n const SEP = path.sep\n\n // automatically compile our given components\n const componentsFullPaths = safeResolves(\n ...tamaguiOptions.components.map(\n (moduleName) => [moduleName, moduleName] as [string, string]\n )\n )\n\n const componentsBaseDirs = Object.entries(componentsFullPaths).map(\n ([_moduleName, fullPath]) => {\n let rootPath = dirname(fullPath as string)\n while (rootPath.length > 1) {\n const pkg = join(rootPath, 'package.json')\n const hasPkg = existsSync(pkg)\n if (hasPkg) {\n return rootPath\n } else {\n rootPath = join(rootPath, '..')\n }\n }\n throw new Error(`Couldn't find package.json in any path above: ${fullPath}`)\n }\n )\n\n function isInComponentModule(fullPath: string) {\n return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir))\n }\n\n // allows configuration\n const shouldExclude = (path: string, projectRoot: string) => {\n const res = tamaguiOptions.shouldExtract?.(path, projectRoot)\n if (typeof res === 'boolean') {\n return !res\n }\n if (isInComponentModule(path)) {\n return false\n }\n return shouldExcludeDefault(path, projectRoot)\n }\n\n const rnw = tamaguiOptions.useReactNativeWebLite\n ? 'react-native-web-lite'\n : 'react-native-web'\n\n const tamaguiAliases = safeResolves(\n ['@tamagui/core/reset.css', '@tamagui/core/reset.css'],\n ['@tamagui/core', '@tamagui/core'],\n ['react-native-svg', '@tamagui/react-native-svg'],\n // fixes https://github.com/kentcdodds/mdx-bundler/issues/143\n ['react/jsx-runtime.js', 'react/jsx-runtime'],\n ['react/jsx-runtime', 'react/jsx-runtime'],\n ['react/jsx-dev-runtime.js', 'react/jsx-dev-runtime'],\n ['react/jsx-dev-runtime', 'react/jsx-dev-runtime'],\n ['react-native-reanimated', 'react-native-reanimated'],\n ['react-native$', rnw],\n ['react-native-web$', rnw],\n ['@testing-library/react-native', '@tamagui/proxy-worm'],\n ['@gorhom/bottom-sheet$', '@gorhom/bottom-sheet'],\n // fix reanimated 3\n ['react-native/Libraries/Renderer/shims/ReactFabric', '@tamagui/proxy-worm'],\n ...(tamaguiOptions.aliasReactPackages\n ? ([\n ['react', 'react'],\n ['react-dom', 'react-dom'],\n ] as any)\n : [])\n )\n\n const alias = {\n ...(webpackConfig.resolve.alias || {}),\n ...tamaguiAliases,\n }\n\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log('Tamagui alias:', alias)\n }\n\n if (process.env.ANALYZE === 'true') {\n Object.assign(webpackConfig.optimization, {\n concatenateModules: false,\n })\n }\n\n webpackConfig.resolve.alias = alias\n\n webpackConfig.plugins.push(\n new webpack.DefinePlugin({\n 'process.env.IS_STATIC': '\"\"',\n 'process.env.TAMAGUI_TARGET': '\"web\"',\n __DEV__: JSON.stringify(dev),\n })\n )\n\n const excludeExports = tamaguiOptions.excludeReactNativeWebExports\n if (Array.isArray(excludeExports)) {\n try {\n const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join('|')}).*js`\n const regex = new RegExp(regexStr)\n // console.log(prefix, 'exclude', regexStr)\n webpackConfig.plugins.push(\n new webpack.NormalModuleReplacementPlugin(regex, resolveEsm('@tamagui/proxy-worm'))\n )\n } catch (err) {\n // eslint-disable-next-line no-console\n console.warn(\n `Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(', ')}`\n )\n }\n }\n\n if (process.env.IGNORE_TS_CONFIG_PATHS) {\n if (process.env.DEBUG) {\n // eslint-disable-next-line no-console\n console.log(prefix, 'ignoring tsconfig paths')\n }\n if (webpackConfig.resolve.plugins[0]) {\n delete webpackConfig.resolve.plugins[0].paths['@tamagui/*']\n delete webpackConfig.resolve.plugins[0].paths['tamagui']\n }\n }\n\n /**\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 cssRules.unshift({\n test: tamaguiOptions.includeCSSTest ?? /\\.css$/,\n sideEffects: true,\n use: getGlobalCssLoader(\n // @ts-ignore\n {\n assetPrefix: options.config.assetPrefix || config.assetPrefix,\n future: nextConfig.future,\n experimental: nextConfig.experimental || {},\n isEdgeRuntime: true,\n isProduction: !dev,\n targetWeb: true,\n isClient: !isServer,\n isServer,\n isDevelopment: dev,\n },\n // @ts-ignore\n () => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),\n []\n ),\n })\n }\n\n webpackConfig.plugins.push(\n new TamaguiPlugin({\n commonjs: isServer,\n exclude: (path: string) => {\n const res = shouldExclude(path, options.dir)\n // console.log(`shouldExclude`, res, path)\n return res\n },\n ...tamaguiOptions,\n })\n )\n\n if (typeof nextConfig.webpack === 'function') {\n return nextConfig.webpack(webpackConfig, options)\n }\n\n return webpackConfig\n },\n }\n }\n}\n\nfunction getSupportedBrowsers(dir, isDevelopment) {\n let browsers\n try {\n browsers = browserslist.loadConfig({\n path: dir,\n env: isDevelopment ? 'development' : 'production',\n })\n } catch {\n //\n }\n return browsers\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,kBAAoC;AAGpC,0BAAyB;AACzB,yBAA0B;AAC1B,iBAA4B;AAC5B,qBAAmC;AACnC,4BAAqE;AACrE,qBAAoB;
|
|
6
|
-
"names": ["buildResolver", "_a", "path", "shouldExcludeDefault", "webpack", "browserslist"]
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,kBAAoC;AAGpC,0BAAyB;AACzB,0CAA+B;AAC/B,yBAA0B;AAC1B,qCAAiC;AACjC,iBAA4B;AAC5B,qBAAmC;AACnC,4BAAqE;AACrE,qBAAoB;AAgBb,MAAM,cAAc,CAAC,mBAAqC;AAC/D,SAAO,CAAC,aAAkB,CAAC,MAAM;AAC/B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,CAAC,eAAoB,YAAiB;AA/BrD;AAgCQ,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,CA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AM;AAAA,MACN,KAAK,gBAAgB,gBAAgB;AAAA,IACvC,CAAC;AAAA,EACH,QAAE;AAAA,EAEF;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["buildResolver", "_a", "path", "shouldExcludeDefault", "webpack", "CssMinimizerPlugin", "MiniCSSExtractPlugin", "browserslist"]
|
|
7
7
|
}
|
package/dist/esm/withTamagui.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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";
|
|
4
5
|
import buildResolver from "esm-resolve";
|
|
6
|
+
import MiniCSSExtractPlugin from "mini-css-extract-plugin";
|
|
5
7
|
import { lazyPostCSS } from "next/dist/build/webpack/config/blocks/css";
|
|
6
8
|
import { getGlobalCssLoader } from "next/dist/build/webpack/config/blocks/css/loaders";
|
|
7
9
|
import { TamaguiPlugin, shouldExclude as shouldExcludeDefault } from "tamagui-loader";
|
|
@@ -24,7 +26,7 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
24
26
|
throw new Error(`Next.js 12 only supported`);
|
|
25
27
|
}
|
|
26
28
|
const prefix = `${isServer ? " ssr " : " web "} |`;
|
|
27
|
-
const safeResolves = (
|
|
29
|
+
const safeResolves = (resolves, multiple = false) => {
|
|
28
30
|
var _a2;
|
|
29
31
|
const res = [];
|
|
30
32
|
for (const [out, mod] of resolves) {
|
|
@@ -34,6 +36,9 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
34
36
|
}
|
|
35
37
|
try {
|
|
36
38
|
res.push([out, resolveEsm(mod)]);
|
|
39
|
+
if (multiple) {
|
|
40
|
+
res.push([out, resolveEsm(mod, true)]);
|
|
41
|
+
}
|
|
37
42
|
} catch (err) {
|
|
38
43
|
if (out.includes(`@gorhom/bottom-sheet`)) {
|
|
39
44
|
continue;
|
|
@@ -43,35 +48,35 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
|
-
return
|
|
51
|
+
return res;
|
|
47
52
|
};
|
|
48
|
-
const resolveEsm = (relativePath) => {
|
|
49
|
-
if (isServer)
|
|
53
|
+
const resolveEsm = (relativePath, onlyRequire = false) => {
|
|
54
|
+
if (isServer || onlyRequire) {
|
|
50
55
|
return require.resolve(relativePath);
|
|
56
|
+
}
|
|
51
57
|
const esm = resolver(relativePath);
|
|
52
58
|
return esm ? path.join(dir, esm) : require.resolve(relativePath);
|
|
53
59
|
};
|
|
54
60
|
const SEP = path.sep;
|
|
55
61
|
const componentsFullPaths = safeResolves(
|
|
56
|
-
|
|
62
|
+
tamaguiOptions.components.map(
|
|
57
63
|
(moduleName) => [moduleName, moduleName]
|
|
58
|
-
)
|
|
64
|
+
),
|
|
65
|
+
true
|
|
59
66
|
);
|
|
60
|
-
const componentsBaseDirs =
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
rootPath = join(rootPath, "..");
|
|
70
|
-
}
|
|
67
|
+
const componentsBaseDirs = componentsFullPaths.map(([_, fullPath]) => {
|
|
68
|
+
let rootPath = dirname(fullPath);
|
|
69
|
+
while (rootPath.length > 1) {
|
|
70
|
+
const pkg = join(rootPath, "package.json");
|
|
71
|
+
const hasPkg = existsSync(pkg);
|
|
72
|
+
if (hasPkg) {
|
|
73
|
+
return rootPath;
|
|
74
|
+
} else {
|
|
75
|
+
rootPath = join(rootPath, "..");
|
|
71
76
|
}
|
|
72
|
-
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
73
77
|
}
|
|
74
|
-
|
|
78
|
+
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
79
|
+
});
|
|
75
80
|
function isInComponentModule(fullPath) {
|
|
76
81
|
return componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir));
|
|
77
82
|
}
|
|
@@ -87,24 +92,26 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
87
92
|
return shouldExcludeDefault(path2, projectRoot);
|
|
88
93
|
};
|
|
89
94
|
const rnw = tamaguiOptions.useReactNativeWebLite ? "react-native-web-lite" : "react-native-web";
|
|
90
|
-
const tamaguiAliases =
|
|
91
|
-
[
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
[
|
|
106
|
-
|
|
107
|
-
|
|
95
|
+
const tamaguiAliases = Object.fromEntries(
|
|
96
|
+
safeResolves([
|
|
97
|
+
["@tamagui/core/reset.css", "@tamagui/core/reset.css"],
|
|
98
|
+
["@tamagui/core", "@tamagui/core"],
|
|
99
|
+
["react-native-svg", "@tamagui/react-native-svg"],
|
|
100
|
+
["react/jsx-runtime.js", "react/jsx-runtime"],
|
|
101
|
+
["react/jsx-runtime", "react/jsx-runtime"],
|
|
102
|
+
["react/jsx-dev-runtime.js", "react/jsx-dev-runtime"],
|
|
103
|
+
["react/jsx-dev-runtime", "react/jsx-dev-runtime"],
|
|
104
|
+
["react-native-reanimated", "react-native-reanimated"],
|
|
105
|
+
["react-native$", rnw],
|
|
106
|
+
["react-native-web$", rnw],
|
|
107
|
+
["@testing-library/react-native", "@tamagui/proxy-worm"],
|
|
108
|
+
["@gorhom/bottom-sheet$", "@gorhom/bottom-sheet"],
|
|
109
|
+
["react-native/Libraries/Renderer/shims/ReactFabric", "@tamagui/proxy-worm"],
|
|
110
|
+
...tamaguiOptions.aliasReactPackages ? [
|
|
111
|
+
["react", "react"],
|
|
112
|
+
["react-dom", "react-dom"]
|
|
113
|
+
] : []
|
|
114
|
+
])
|
|
108
115
|
);
|
|
109
116
|
const alias = {
|
|
110
117
|
...webpackConfig.resolve.alias || {},
|
|
@@ -149,6 +156,18 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
149
156
|
delete webpackConfig.resolve.plugins[0].paths["tamagui"];
|
|
150
157
|
}
|
|
151
158
|
}
|
|
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
|
+
}
|
|
152
171
|
if (isServer) {
|
|
153
172
|
const externalize = (context, request) => {
|
|
154
173
|
const fullPath = request[0] === "." ? path.join(context, request) : request;
|
|
@@ -227,24 +246,46 @@ const withTamagui = (tamaguiOptions) => {
|
|
|
227
246
|
]
|
|
228
247
|
});
|
|
229
248
|
}
|
|
249
|
+
const cssLoader = getGlobalCssLoader(
|
|
250
|
+
{
|
|
251
|
+
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
252
|
+
future: nextConfig.future,
|
|
253
|
+
experimental: nextConfig.experimental || {},
|
|
254
|
+
isEdgeRuntime: true,
|
|
255
|
+
isProduction: !dev,
|
|
256
|
+
targetWeb: true,
|
|
257
|
+
isClient: !isServer,
|
|
258
|
+
isServer,
|
|
259
|
+
isDevelopment: dev
|
|
260
|
+
},
|
|
261
|
+
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
262
|
+
[]
|
|
263
|
+
);
|
|
264
|
+
const cssTest = tamaguiOptions.includeCSSTest ?? /\.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
|
+
}
|
|
230
285
|
cssRules.unshift({
|
|
231
|
-
test:
|
|
286
|
+
test: cssTest,
|
|
232
287
|
sideEffects: true,
|
|
233
|
-
use:
|
|
234
|
-
{
|
|
235
|
-
assetPrefix: options.config.assetPrefix || config.assetPrefix,
|
|
236
|
-
future: nextConfig.future,
|
|
237
|
-
experimental: nextConfig.experimental || {},
|
|
238
|
-
isEdgeRuntime: true,
|
|
239
|
-
isProduction: !dev,
|
|
240
|
-
targetWeb: true,
|
|
241
|
-
isClient: !isServer,
|
|
242
|
-
isServer,
|
|
243
|
-
isDevelopment: dev
|
|
244
|
-
},
|
|
245
|
-
() => lazyPostCSS(dir, getSupportedBrowsers(dir, dev)),
|
|
246
|
-
[]
|
|
247
|
-
)
|
|
288
|
+
use: cssLoader
|
|
248
289
|
});
|
|
249
290
|
}
|
|
250
291
|
webpackConfig.plugins.push(
|