-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnext.config.mjs
118 lines (101 loc) · 3 KB
/
next.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
116
117
118
/** @type {import('next').NextConfig} */
// const CopyPlugin = require("copy-webpack-plugin");
// TODO: try react compiler when stable
const extsRegExp = exts => new RegExp(`\\.(${exts.join("|")})$`, "i");
const nextConfig = {
// https://stackoverflow.com/questions/60618844/react-hooks-useeffect-is-called-twice-even-if-an-empty-array-is-used-as-an-ar
reactStrictMode: false,
images: {
remotePatterns: [
{ protocol: "https", hostname: "i.scdn.co" },
{ protocol: "https", hostname: "live.staticflickr.com" },
{ protocol: "https", hostname: "media.sketchfab.com" },
{ protocol: "https", hostname: "media.discordapp.net" },
{ protocol: "https", hostname: "static.wikia.nocookie.net" },
{ protocol: "https", hostname: "mastodon.hotmilk.space" },
{ protocol: "https", hostname: "static-cdn.jtvnw.net" },
{ protocol: "https", hostname: "img.youtube.com" },
],
},
i18n: {
locales: ["en"],
defaultLocale: "en",
},
experimental: {
reactCompiler: true,
},
webpack: (config, { isServer }) => {
// config.experiments = { ...config.experiments, asyncWebAssembly: true };
// config.plugins = [
// ...config.plugins,
// new CopyPlugin({
// patterns: [
// {
// from: "node_modules/three/examples/jsm/libs/draco/",
// to: "./static/libs/draco/",
// },
// ],
// }),
// ];
const prefix = config.assetPrefix ?? config.basePath ?? "";
// config.module.rules.push({
// test: extsRegExp([...imageExts, ...otherExts]),
// use: [
// {
// loader: "url-loader",
// options: {
// limit: 8192,
// fallback: "file-loader",
// publicPath: `${prefix}/_next/static/media/`,
// outputPath: `${isServer ? "../" : ""}static/images/`,
// name: "[name].[hash:8].[ext]",
// },
// },
// ],
// });
// when ?inline use url-loader
const imageLoaderRule = config.module.rules.find(
rule => rule.loader == "next-image-loader",
);
imageLoaderRule.resourceQuery = { not: [/inline/] };
imageLoaderRule.exclude = /\.(svg)$/i;
// const urlLoader = {
// loader: "url-loader",
// options: {
// generator: content => svgToMiniDataURI(content.toString()),
// },
// };
// anything with ?inline except svg becomes data uri
config.module.rules.push({
exclude: /\.(svg)$/i,
resourceQuery: /inline/,
use: ["url-loader"],
});
// all svgs turn minified
config.module.rules.push({
test: /\.(svg)$/i,
use: ["url-loader", "svgo-loader"], // order is reversed wtf
});
// config.module.rules.push({
// test: /\.(svg)$/i,
// resourceQuery: /component/,
// use: ["@svgr/webpack"],
// });
// add more files to file loading via url
config.module.rules.push({
test: extsRegExp(["mp4", "webm", "tar"]),
use: [
{
loader: "file-loader",
options: {
publicPath: `${prefix}/_next/static/media/`,
outputPath: `${isServer ? "../" : ""}static/media/`,
name: "[name].[hash:8].[ext]",
},
},
],
});
return config;
},
};
export default nextConfig;