Skip to content

Commit bae1acb

Browse files
committed
Handle asset/resource like Webpack should
1 parent afc64e8 commit bae1acb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

next.config.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const ALLOWED_SVG_REGEX = new RegExp(`${sep}icons${sep}.+\\.svg$`)
3737
const config = {
3838
output: undefined,
3939
// reactStrictMode: true, provoke duplicated codemirror editors
40-
webpack(config) {
40+
webpack(config, { isServer, dev }) {
4141
// #region MDX
4242
const mdxRule = config.module.rules.find(rule => rule.test?.test?.(".mdx"))
4343
if (mdxRule) {
@@ -62,6 +62,19 @@ const config = {
6262
fileLoaderRule.exclude = /\.svg$/i
6363

6464
config.module.rules.push(
65+
{
66+
test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg|txt)$/i,
67+
resourceQuery: /resource/,
68+
type: "asset/resource",
69+
generator: {
70+
filename: "static/media/[name].[hash][ext]",
71+
publicPath: "/_next/",
72+
// Server build outputs to .next/server/, so go up to reach .next/static/
73+
outputPath: [isServer && "../", !dev && "../"]
74+
.filter(Boolean)
75+
.join(""),
76+
},
77+
},
6578
// All .svg from /icons/ and with ?svgr are going to be processed by @svgr/webpack
6679
{
6780
test: ALLOWED_SVG_REGEX,
@@ -103,7 +116,7 @@ const config = {
103116
test: /\.svg$/i,
104117
exclude: ALLOWED_SVG_REGEX,
105118
resourceQuery: {
106-
not: [...fileLoaderRule.resourceQuery.not, /svgr/],
119+
not: [...fileLoaderRule.resourceQuery.not, /svgr|resource/],
107120
},
108121
},
109122
)

0 commit comments

Comments
 (0)