-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnext.config.js
40 lines (37 loc) · 1.02 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
const unwrapImages = require("remark-unwrap-images")
const path = require("path")
const fs = require("fs-extra")
const webpack = require("webpack")
const withMDX = require("@next/mdx")({
options: {
remarkPlugins: [unwrapImages],
},
})
const fetchFiles = (filePath) => {
const files = fs.readdirSync(filePath)
return files.reduce((acc, file) => {
const elName = path.basename(file, ".js")
return {
...acc,
[elName]: [`${filePath}/${file}`, "default"],
}
}, {})
}
module.exports = withMDX({
webpack: (config, {}) => {
const elements = fetchFiles(path.join(__dirname, "elements"))
const components = fetchFiles(path.join(__dirname, "components"))
config.plugins.push(
new webpack.ProvidePlugin(elements),
new webpack.ProvidePlugin(components)
)
config.resolve = {
alias: {
...(config.resolve.alias || {}),
elements: path.resolve(__dirname, "elements/"),
components: path.resolve(__dirname, "components/"),
},
}
return config
},
})