/
next.config.js
99 lines (87 loc) · 2.09 KB
/
next.config.js
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
/** @type {import('next').NextConfig} */
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const matter = require('gray-matter')
const highlight = require('./lib/highlighter.js')
const getPosts = fromPath => {
const paths = glob.sync(`${path.join(fromPath)}/**/*.mdx`)
return paths.map(filePath => {
const source = fs.readFileSync(path.join(filePath), 'utf8')
const { data } = matter(source)
return {
frontmatter: data,
}
})
}
const i18n = {
locales: ['ru', 'en'],
defaultLocale: 'ru',
localeDetection: false,
}
const nextConfig = {
reactStrictMode: true,
pageExtensions: ['tsx', 'ts'],
i18n,
webpack(config, options) {
;(config.module.rules = config.module.rules.concat([
{
test: /\.mdx?$/,
use: [
options.defaultLoaders.babel,
{
loader: require.resolve('@mdx-js/loader'),
options: {
remarkPlugins: [],
rehypePlugins: [highlight],
providerImportSource: '@mdx-js/react',
},
},
{
loader: require.resolve('./lib/frontmatterLoader.js'),
options: {},
},
],
},
{
test: /\.svg$/i,
issuer: /\.([jt]s|md)x?$/,
use: [
{
loader: '@svgr/webpack',
options: {
throwIfNamespace: false,
},
},
],
},
{
test: /\.graphql$/i,
use: [
{
loader: 'raw-loader',
},
],
},
])),
config.plugins.push(
new options.webpack.DefinePlugin({
__POSTS__: JSON.stringify(
getPosts(path.resolve(__dirname, './blog'))
),
})
)
config.experiments.asyncWebAssembly = true
config.experiments.syncWebAssembly = true
config.output.webassemblyModuleFilename = 'static/wasm/[modulehash].wasm'
return config
},
redirects: () => [
{
source: '/',
destination: '/blog',
permanent: true,
},
],
}
module.exports = nextConfig