Skip to content

Instantly share code, notes, and snippets.

@nilsandrey
Last active May 2, 2024 02:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsandrey/ebcae24d844e76915e60047e5b63190b to your computer and use it in GitHub Desktop.
Save nilsandrey/ebcae24d844e76915e60047e5b63190b to your computer and use it in GitHub Desktop.
Use of config.resolve.alias in NextJS config
// Copied for easier bookmarking from <https://github.com/vercel/next.js/issues/706#issuecomment-569041997> by @Lwdthe1
// next.config.js
const aliasPathsToResolve = [
{ name: 'components', path: path.resolve(__dirname, './components') },
{ name: 'Common', path: path.resolve(__dirname, '../../common/react/') },
]
module.exports = () => {
return {
webpack(config, { defaultLoaders }) {
config.module.rules.push({
test: /\.(js|jsx)$/,
include: [path.resolve(__dirname, '../../common/react/')],
use: [defaultLoaders.babel],
})
/** Resolve aliases */
aliasPathsToResolve.forEach((module) => {
config.resolve.alias[module.name] = module.path
})
}
}
}
@nilsandrey
Copy link
Author

Copied for easier bookmarking from vercel/next.js#706 (comment) by @Lwdthe1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment