@wyw-in-js/nextjs 1.1.0 → 2.0.0-alpha.0
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/README.md +5 -5
- package/esm/index.mjs +265 -349
- package/esm/index.mjs.map +1 -1
- package/package.json +12 -13
- package/types/index.d.ts +2 -1
- package/types/index.js +25 -86
- package/lib/index.js +0 -394
- package/lib/index.js.map +0 -1
package/esm/index.mjs
CHANGED
|
@@ -1,382 +1,298 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
const DEFAULT_EXTENSION = ".wyw-in-js.module.css";
|
|
3
|
+
const DEFAULT_TURBO_RULE_KEYS = [
|
|
4
|
+
"*.js",
|
|
5
|
+
"*.jsx",
|
|
6
|
+
"*.ts",
|
|
7
|
+
"*.tsx"
|
|
8
|
+
];
|
|
5
9
|
const DEFAULT_REACT_IMPORT_OVERRIDES = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'react/jsx-runtime': {
|
|
10
|
-
mock: 'react/jsx-runtime'
|
|
11
|
-
},
|
|
12
|
-
'react/jsx-dev-runtime': {
|
|
13
|
-
mock: 'react/jsx-dev-runtime'
|
|
14
|
-
}
|
|
10
|
+
react: { mock: "react" },
|
|
11
|
+
"react/jsx-runtime": { mock: "react/jsx-runtime" },
|
|
12
|
+
"react/jsx-dev-runtime": { mock: "react/jsx-dev-runtime" }
|
|
15
13
|
};
|
|
16
|
-
const
|
|
17
|
-
const PLACEHOLDER_IGNORED_DIRS = new Set(['.git', '.next', '.turbo', 'node_modules']);
|
|
14
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
18
15
|
function isObject(value) {
|
|
19
|
-
|
|
16
|
+
return typeof value === "object" && value !== null;
|
|
20
17
|
}
|
|
21
18
|
function isUseLoaderObject(item) {
|
|
22
|
-
|
|
19
|
+
return isObject(item) && typeof item.loader === "string";
|
|
23
20
|
}
|
|
24
21
|
function normalizeUseItems(use) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
if (!use) return null;
|
|
23
|
+
if (typeof use === "function") return null;
|
|
24
|
+
const list = (Array.isArray(use) ? use : [use]).filter(Boolean);
|
|
25
|
+
return list.length ? list : null;
|
|
29
26
|
}
|
|
30
27
|
function getLoaderName(item) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
if (typeof item === "string") return item;
|
|
29
|
+
if (isUseLoaderObject(item)) return item.loader;
|
|
30
|
+
return "";
|
|
34
31
|
}
|
|
35
32
|
function isWywLoaderPath(loader) {
|
|
36
|
-
|
|
33
|
+
return loader.includes("@wyw-in-js/webpack-loader") || /[\\/]webpack-loader[\\/]/.test(loader);
|
|
37
34
|
}
|
|
38
35
|
function convertLoaderRuleToUseRule(rule, wywLoaderItem) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
...(options !== undefined ? {
|
|
59
|
-
options
|
|
60
|
-
} : {})
|
|
61
|
-
}, wywLoaderItem]
|
|
62
|
-
});
|
|
36
|
+
const { loader } = rule;
|
|
37
|
+
if (typeof loader !== "string") return;
|
|
38
|
+
const alreadyInjected = isWywLoaderPath(loader);
|
|
39
|
+
if (alreadyInjected) return;
|
|
40
|
+
const isNextJsTranspileRule = [
|
|
41
|
+
"next-swc-loader",
|
|
42
|
+
"next-babel-loader",
|
|
43
|
+
"babel-loader"
|
|
44
|
+
].some((needle) => loader.includes(needle));
|
|
45
|
+
if (!isNextJsTranspileRule) return;
|
|
46
|
+
const { options } = rule;
|
|
47
|
+
const nextRule = rule;
|
|
48
|
+
delete nextRule.loader;
|
|
49
|
+
delete nextRule.options;
|
|
50
|
+
// Loader order is right-to-left. We want WyW to run first, so it should be last.
|
|
51
|
+
Object.assign(nextRule, { use: [{
|
|
52
|
+
loader,
|
|
53
|
+
...options !== undefined ? { options } : {}
|
|
54
|
+
}, wywLoaderItem] });
|
|
63
55
|
}
|
|
64
56
|
function traverseRules(rules, visitor) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
for (const rule of rules) {
|
|
58
|
+
if (rule && typeof rule === "object") {
|
|
59
|
+
visitor(rule);
|
|
60
|
+
if (Array.isArray(rule.oneOf)) {
|
|
61
|
+
traverseRules(rule.oneOf, visitor);
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(rule.rules)) {
|
|
64
|
+
traverseRules(rule.rules, visitor);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
76
68
|
}
|
|
77
69
|
function escapeRegExp(value) {
|
|
78
|
-
|
|
70
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
79
71
|
}
|
|
80
72
|
function isPlainObject(value) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
if (!isObject(value)) return false;
|
|
74
|
+
const proto = Object.getPrototypeOf(value);
|
|
75
|
+
return proto === Object.prototype || proto === null;
|
|
84
76
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
77
|
+
function assertJsonSerializable(value, name) {
|
|
78
|
+
const queue = [{
|
|
79
|
+
path: name,
|
|
80
|
+
value
|
|
81
|
+
}];
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
while (queue.length) {
|
|
84
|
+
const current = queue.shift();
|
|
85
|
+
if (current.value === null) {} else if (typeof current.value === "undefined") {} else if (typeof current.value === "string" || typeof current.value === "number" || typeof current.value === "boolean") {} else if (typeof current.value === "function" || typeof current.value === "symbol" || typeof current.value === "bigint") {
|
|
86
|
+
throw new Error(`${current.path} must be JSON-serializable (functions, symbols and bigint are not supported in Turbopack loader options). Use "configFile" to pass non-JSON config.`);
|
|
87
|
+
} else if (Array.isArray(current.value)) {
|
|
88
|
+
if (!seen.has(current.value)) {
|
|
89
|
+
seen.add(current.value);
|
|
90
|
+
current.value.forEach((item, idx) => queue.push({
|
|
91
|
+
path: `${current.path}[${idx}]`,
|
|
92
|
+
value: item
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
} else if (isPlainObject(current.value)) {
|
|
96
|
+
if (!seen.has(current.value)) {
|
|
97
|
+
seen.add(current.value);
|
|
98
|
+
Object.entries(current.value).forEach(([key, item]) => queue.push({
|
|
99
|
+
path: `${current.path}.${key}`,
|
|
100
|
+
value: item
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
throw new Error(`${current.path} must be JSON-serializable (only plain objects, arrays, and primitives are supported in Turbopack loader options). Use "configFile" to pass non-JSON config.`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
116
107
|
}
|
|
117
108
|
function createWywCssModuleRule(baseRule, extensionSuffix) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
return nextRule;
|
|
109
|
+
const use = normalizeUseItems(baseRule.use) ?? [];
|
|
110
|
+
const patchedUse = use.map((item) => {
|
|
111
|
+
if (!isUseLoaderObject(item) || !item.loader.includes("css-loader")) {
|
|
112
|
+
return item;
|
|
113
|
+
}
|
|
114
|
+
const itemOptions = item.options;
|
|
115
|
+
if (!isObject(itemOptions)) {
|
|
116
|
+
return item;
|
|
117
|
+
}
|
|
118
|
+
const { modules } = itemOptions;
|
|
119
|
+
if (!isObject(modules)) {
|
|
120
|
+
return item;
|
|
121
|
+
}
|
|
122
|
+
const nextModules = {
|
|
123
|
+
...modules,
|
|
124
|
+
mode: "global",
|
|
125
|
+
getLocalIdent: (_context, _localIdentName, localName) => localName
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
...item,
|
|
129
|
+
options: {
|
|
130
|
+
...itemOptions,
|
|
131
|
+
modules: nextModules
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
const nextRule = {
|
|
136
|
+
...baseRule,
|
|
137
|
+
sideEffects: true,
|
|
138
|
+
test: new RegExp(`${escapeRegExp(extensionSuffix)}$`),
|
|
139
|
+
use: patchedUse
|
|
140
|
+
};
|
|
141
|
+
return nextRule;
|
|
153
142
|
}
|
|
154
143
|
function ensureWywCssModuleRules(config, extensionSuffix) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
144
|
+
traverseRules(config.module?.rules ?? [], (rule) => {
|
|
145
|
+
if (!Array.isArray(rule.oneOf) || rule.oneOf.length === 0) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const expectedTestSource = `${escapeRegExp(extensionSuffix)}$`;
|
|
149
|
+
const alreadyPresent = rule.oneOf.some((candidate) => {
|
|
150
|
+
if (!candidate || typeof candidate !== "object") return false;
|
|
151
|
+
const { test } = candidate;
|
|
152
|
+
return test instanceof RegExp && test.source === expectedTestSource;
|
|
153
|
+
});
|
|
154
|
+
if (alreadyPresent) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const oneOf = rule.oneOf;
|
|
158
|
+
for (let idx = 0; idx < oneOf.length; idx += 1) {
|
|
159
|
+
const candidate = oneOf[idx];
|
|
160
|
+
if (candidate && typeof candidate === "object") {
|
|
161
|
+
const candidateRule = candidate;
|
|
162
|
+
const { test } = candidateRule;
|
|
163
|
+
const isModuleCssRule = test instanceof RegExp && test.source.includes("\\.module\\.css");
|
|
164
|
+
if (isModuleCssRule) {
|
|
165
|
+
const use = normalizeUseItems(candidateRule.use);
|
|
166
|
+
if (use) {
|
|
167
|
+
const hasCssLoader = use.some((item) => isUseLoaderObject(item) && item.loader.includes("css-loader"));
|
|
168
|
+
if (hasCssLoader) {
|
|
169
|
+
oneOf.splice(idx, 0, createWywCssModuleRule(candidateRule, extensionSuffix));
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
192
177
|
}
|
|
193
178
|
function injectWywLoader(config, nextOptions, wywNext) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// Loader order is right-to-left. We want WyW to run first, so it should be last.
|
|
230
|
-
Object.assign(rule, {
|
|
231
|
-
use: [...use, wywLoaderItem]
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
ensureWywCssModuleRules(config, extension);
|
|
235
|
-
}
|
|
236
|
-
function ensureTurbopackCssPlaceholders(projectRoot) {
|
|
237
|
-
const queue = [projectRoot];
|
|
238
|
-
while (queue.length) {
|
|
239
|
-
const dir = queue.pop();
|
|
240
|
-
let entries;
|
|
241
|
-
try {
|
|
242
|
-
entries = fs.readdirSync(dir, {
|
|
243
|
-
withFileTypes: true
|
|
244
|
-
});
|
|
245
|
-
} catch {
|
|
246
|
-
entries = [];
|
|
247
|
-
}
|
|
248
|
-
for (const entry of entries) {
|
|
249
|
-
if (entry.name !== '.' && entry.name !== '..') {
|
|
250
|
-
const entryPath = path.join(dir, entry.name);
|
|
251
|
-
if (entry.isDirectory()) {
|
|
252
|
-
if (!PLACEHOLDER_IGNORED_DIRS.has(entry.name)) {
|
|
253
|
-
queue.push(entryPath);
|
|
254
|
-
}
|
|
255
|
-
} else if (entry.isFile()) {
|
|
256
|
-
const shouldIgnore = entry.name.startsWith('middleware.') || entry.name.endsWith('.d.ts');
|
|
257
|
-
if (!shouldIgnore) {
|
|
258
|
-
const ext = path.extname(entry.name);
|
|
259
|
-
if (PLACEHOLDER_EXTENSIONS.has(ext)) {
|
|
260
|
-
const baseName = path.basename(entry.name, ext);
|
|
261
|
-
const cssFilePath = path.join(path.dirname(entryPath), `${baseName}${DEFAULT_EXTENSION}`);
|
|
262
|
-
try {
|
|
263
|
-
fs.writeFileSync(cssFilePath, '', {
|
|
264
|
-
flag: 'wx'
|
|
265
|
-
});
|
|
266
|
-
} catch (err) {
|
|
267
|
-
if (err.code !== 'EEXIST') {
|
|
268
|
-
throw err;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
179
|
+
const loader = nodeRequire.resolve("@wyw-in-js/webpack-loader");
|
|
180
|
+
const extension = wywNext.loaderOptions?.extension ?? DEFAULT_EXTENSION;
|
|
181
|
+
const userImportOverrides = wywNext.loaderOptions?.importOverrides;
|
|
182
|
+
const importOverrides = userImportOverrides ? {
|
|
183
|
+
...DEFAULT_REACT_IMPORT_OVERRIDES,
|
|
184
|
+
...userImportOverrides
|
|
185
|
+
} : DEFAULT_REACT_IMPORT_OVERRIDES;
|
|
186
|
+
const loaderOptions = {
|
|
187
|
+
cssImport: "import",
|
|
188
|
+
...wywNext.loaderOptions,
|
|
189
|
+
extension,
|
|
190
|
+
importOverrides,
|
|
191
|
+
sourceMap: wywNext.loaderOptions?.sourceMap ?? nextOptions.dev
|
|
192
|
+
};
|
|
193
|
+
const wywLoaderItem = {
|
|
194
|
+
loader,
|
|
195
|
+
options: loaderOptions
|
|
196
|
+
};
|
|
197
|
+
traverseRules(config.module?.rules ?? [], (rule) => {
|
|
198
|
+
convertLoaderRuleToUseRule(rule, wywLoaderItem);
|
|
199
|
+
const use = normalizeUseItems(rule.use);
|
|
200
|
+
if (!use) return;
|
|
201
|
+
const loaders = use.map(getLoaderName);
|
|
202
|
+
const alreadyInjected = loaders.some((l) => l === loader || isWywLoaderPath(l));
|
|
203
|
+
if (alreadyInjected) return;
|
|
204
|
+
const isNextJsTranspileRule = loaders.some((l) => [
|
|
205
|
+
"next-swc-loader",
|
|
206
|
+
"next-babel-loader",
|
|
207
|
+
"babel-loader"
|
|
208
|
+
].some((needle) => l.includes(needle)));
|
|
209
|
+
if (!isNextJsTranspileRule) return;
|
|
210
|
+
// Loader order is right-to-left. We want WyW to run first, so it should be last.
|
|
211
|
+
Object.assign(rule, { use: [...use, wywLoaderItem] });
|
|
212
|
+
});
|
|
213
|
+
ensureWywCssModuleRules(config, extension);
|
|
277
214
|
}
|
|
278
215
|
function shouldUseTurbopackConfig(nextConfig) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
216
|
+
const explicit = nextConfig.turbopack;
|
|
217
|
+
if (typeof explicit !== "undefined") {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const pkgPath = nodeRequire.resolve("next/package.json", { paths: [process.cwd()] });
|
|
222
|
+
const pkg = nodeRequire(pkgPath);
|
|
223
|
+
const version = typeof pkg.version === "string" ? pkg.version : "";
|
|
224
|
+
const major = Number.parseInt(version.split(".")[0] ?? "", 10);
|
|
225
|
+
return Number.isFinite(major) && major >= 16;
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
294
229
|
}
|
|
295
230
|
function injectWywTurbopackRules(nextConfig, wywNext) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
const userExperimental = isPlainObject(nextConfig.experimental) ? nextConfig.experimental : {};
|
|
355
|
-
const userTurbo = isPlainObject(userExperimental.turbo) ? userExperimental.turbo : {};
|
|
356
|
-
const userRules = isPlainObject(userTurbo.rules) ? userTurbo.rules : {};
|
|
357
|
-
return {
|
|
358
|
-
...nextConfig,
|
|
359
|
-
experimental: {
|
|
360
|
-
...userExperimental,
|
|
361
|
-
turbo: {
|
|
362
|
-
...userTurbo,
|
|
363
|
-
rules: {
|
|
364
|
-
...wywRules,
|
|
365
|
-
...userRules
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
231
|
+
const loader = nodeRequire.resolve("@wyw-in-js/turbopack-loader");
|
|
232
|
+
const userOptions = wywNext.turbopackLoaderOptions ?? {};
|
|
233
|
+
assertJsonSerializable(userOptions, "turbopackLoaderOptions");
|
|
234
|
+
const userImportOverrides = isPlainObject(userOptions.importOverrides) ? userOptions.importOverrides : undefined;
|
|
235
|
+
const loaderOptions = {
|
|
236
|
+
sourceMap: process.env.NODE_ENV !== "production",
|
|
237
|
+
...userOptions,
|
|
238
|
+
importOverrides: userImportOverrides ? {
|
|
239
|
+
...DEFAULT_REACT_IMPORT_OVERRIDES,
|
|
240
|
+
...userImportOverrides
|
|
241
|
+
} : DEFAULT_REACT_IMPORT_OVERRIDES
|
|
242
|
+
};
|
|
243
|
+
const useTurbopackConfig = shouldUseTurbopackConfig(nextConfig);
|
|
244
|
+
const ruleValue = useTurbopackConfig ? {
|
|
245
|
+
loaders: [{
|
|
246
|
+
loader,
|
|
247
|
+
options: loaderOptions
|
|
248
|
+
}],
|
|
249
|
+
condition: { all: [{ not: "foreign" }, { not: { path: /(?:^|[\\/])middleware\.[jt]sx?$/ } }] }
|
|
250
|
+
} : [{
|
|
251
|
+
loader,
|
|
252
|
+
options: loaderOptions
|
|
253
|
+
}];
|
|
254
|
+
const wywRules = Object.fromEntries(DEFAULT_TURBO_RULE_KEYS.map((key) => [key, ruleValue]));
|
|
255
|
+
if (useTurbopackConfig) {
|
|
256
|
+
const turbopackConfig = nextConfig.turbopack;
|
|
257
|
+
const userTurbopack = isPlainObject(turbopackConfig) ? turbopackConfig : {};
|
|
258
|
+
const userRules = isPlainObject(userTurbopack.rules) ? userTurbopack.rules : {};
|
|
259
|
+
return {
|
|
260
|
+
...nextConfig,
|
|
261
|
+
turbopack: {
|
|
262
|
+
...userTurbopack,
|
|
263
|
+
rules: {
|
|
264
|
+
...wywRules,
|
|
265
|
+
...userRules
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const userExperimental = isPlainObject(nextConfig.experimental) ? nextConfig.experimental : {};
|
|
271
|
+
const userTurbo = isPlainObject(userExperimental.turbo) ? userExperimental.turbo : {};
|
|
272
|
+
const userRules = isPlainObject(userTurbo.rules) ? userTurbo.rules : {};
|
|
273
|
+
return {
|
|
274
|
+
...nextConfig,
|
|
275
|
+
experimental: {
|
|
276
|
+
...userExperimental,
|
|
277
|
+
turbo: {
|
|
278
|
+
...userTurbo,
|
|
279
|
+
rules: {
|
|
280
|
+
...wywRules,
|
|
281
|
+
...userRules
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
370
286
|
}
|
|
371
287
|
export function withWyw(nextConfig = {}, wywNext = {}) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
288
|
+
const userWebpack = nextConfig.webpack;
|
|
289
|
+
return {
|
|
290
|
+
...injectWywTurbopackRules(nextConfig, wywNext),
|
|
291
|
+
webpack(config, options) {
|
|
292
|
+
const resolvedConfig = typeof userWebpack === "function" ? userWebpack(config, options) : config;
|
|
293
|
+
injectWywLoader(resolvedConfig, options, wywNext);
|
|
294
|
+
return resolvedConfig;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
381
297
|
}
|
|
382
|
-
//# sourceMappingURL=index.mjs.map
|
|
298
|
+
//# sourceMappingURL=index.mjs.map
|