Created
March 1, 2023 21:29
-
-
Save doramatadora/377450b576d79a5b9c30e22d17ba5166 to your computer and use it in GitHub Desktop.
Next.JS webpack config change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
reactStrictMode: true, | |
webpack: (config, options) => { | |
config.externals = [ | |
({request,}, callback) => { | |
// Allow Webpack to handle fastly:* namespaced module imports by treating | |
// them as modules rather than try to process them as URLs | |
if (/^fastly:.*$/.test(request)) { | |
return callback(null, 'commonjs ' + request); | |
} | |
callback(); | |
} | |
]; | |
return config | |
}, | |
async headers() { | |
return [ | |
{ | |
source: '/foo', | |
headers: [ | |
{ | |
key: 'x-custom-header', | |
value: 'my custom header value', | |
}, | |
], | |
}, | |
] | |
}, | |
}; | |
if (!process.env.NEXT_COMPUTE_JS) { | |
// Apply MDX loader only at compile time | |
const withMDX = require('@next/mdx')({ | |
extension: /\.mdx?$/, | |
options: { | |
remarkPlugins: [], | |
rehypePlugins: [], | |
}, | |
}); | |
module.exports = withMDX({ | |
...module.exports, | |
// Append the default value with md extensions | |
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'], | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment