-
Notifications
You must be signed in to change notification settings - Fork 50
/
next.config.js
80 lines (76 loc) · 2.06 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
// $FlowIssue this is what mapbox/rehype-prism uses under the hood
const refract = require("refractor");
// NOTE: This highlights template-strings as strings of CSS
const styledHighlight = {
"styled-template-string": {
pattern: /(styled(\.\w+|\([^\)]*\))(\.\w+(\([^\)]*\))*)*|css|injectGlobal|createGlobalStyle|keyframes|\.extend|\.withComponent)`(?:\$\{[^}]+\}|\\\\|\\?[^\\])*?`/,
lookbehind: true,
greedy: true,
inside: {
interpolation: {
pattern: /\$\{[^}]+\}/,
inside: {
"interpolation-punctuation": {
pattern: /^\$\{|\}$/,
alias: "punctuation"
},
rest: refract.languages.jsx
}
},
string: {
pattern: /[^$;]+/,
inside: refract.languages.css,
alias: "language-css"
}
}
}
};
refract.languages.insertBefore("jsx", "template-string", styledHighlight);
refract.languages.insertBefore("js", "template-string", styledHighlight);
const withMDX = require("@next/mdx")({
extension: /\.mdx?$/,
options: {
// $FlowIssue
hastPlugins: [require("@mapbox/rehype-prism")]
}
});
const fs = require("fs");
const { join } = require("path");
const generateJsonFeed = require("./data/generate-json-feed");
const { promisify } = require("util");
const copyFile = promisify(fs.copyFile);
const staticFilesToCopy = ["favicon.ico"];
module.exports = withMDX({
pageExtensions: ["js", "jsx", "mdx", "md"],
exportPathMap: async function(
defaultPathMap,
{ dev, dir, outDir, distDir, buildId }
) {
if (dev) return defaultPathMap;
generateJsonFeed(outDir);
await Promise.all(
staticFilesToCopy.map(file =>
copyFile(join(dir, file), join(outDir, file))
)
);
return defaultPathMap;
},
webpack(config, options) {
config.module.rules.push({
test: /.svg$/,
use: [
{
loader: "@svgr/webpack",
options: {
icon: true
}
}
]
});
config.module.rules.push({
test: /.css$/,
use: "raw-loader"
});
return config;
}
});