-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.ts
96 lines (87 loc) · 2.91 KB
/
next.config.ts
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
import type { NextConfig } from 'next'
import createMDX from "@next/mdx";
import rehypeUnwrapImages from "rehype-unwrap-images";
import remarkGfm from "remark-gfm";
import remarkExtendedTable, {
extendedTableHandlers,
} from "remark-extended-table";
import { RuleSetRule } from 'webpack';
const withMDX = createMDX({
// Add markdown plugins here, as desired
options: {
remarkPlugins: [remarkGfm, remarkExtendedTable],
rehypePlugins: [rehypeUnwrapImages],
remarkRehypeOptions: { handlers: { ...extendedTableHandlers } },
},
});
const nextConfig: NextConfig = {
webpack(config) {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule: RuleSetRule) =>
rule.test instanceof RegExp && rule.test?.test?.(".svg"),
);
config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
use: [
{
loader: "@svgr/webpack",
options: {
svgoConfig: {
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false,
cleanupIds: false,
},
},
},
],
},
},
},
],
},
{
test: /\.md$/i,
use: "raw-loader",
},
);
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i;
return config;
},
output: "export",
images: {
loader: "custom",
imageSizes: [256, 384],
deviceSizes: [640, 750, 828, 1080],
},
transpilePackages: ["next-image-export-optimizer"],
env: {
nextImageExportOptimizer_imageFolderPath: "public/images",
nextImageExportOptimizer_exportFolderPath: "out",
nextImageExportOptimizer_quality: "90",
nextImageExportOptimizer_storePicturesInWEBP: "true",
nextImageExportOptimizer_exportFolderName: "optimized",
// If you do not want to use blurry placeholder images, then you can set
// nextImageExportOptimizer_generateAndUseBlurImages to false and pass
// `placeholder="empty"` to all <ExportedImage> components.
nextImageExportOptimizer_generateAndUseBlurImages: "true",
// If you want to cache the remote images, you can set the time to live of the cache in seconds.
// The default value is 0 seconds.
nextImageExportOptimizer_remoteImageCacheTTL: "0",
},
};
export default withMDX(nextConfig);