Skip to content

Instantly share code, notes, and snippets.

@lfades
Created October 13, 2017 16:35
Show Gist options
  • Save lfades/797b165bf2574594509756ba77856bc0 to your computer and use it in GitHub Desktop.
Save lfades/797b165bf2574594509756ba77856bc0 to your computer and use it in GitHub Desktop.
Using separated babel config for server and client in Nextjs
{
"presets": ["node8"],
"plugins": [
["module-resolver", {
"root": ["."],
"alias": {
"~": "./server"
}
}]
]
}
module.exports = {
webpack: config => {
// This is the rule next is using for our .babelrc
const babelRule = config.module.rules.find(rule => (
rule.loader === 'babel-loader' && rule.options.babelrc === true
))
// Add the babel configuration from here and ignore the .babelrc cause
// it will be used for the server
Object.assign(babelRule.options, {
babelrc: false,
presets: ['next/babel'],
plugins: [
['module-resolver', {
root: ['.'],
alias: {
'~': './modules'
}
}]
]
})
return config
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment