Created
October 13, 2017 16:35
-
-
Save lfades/797b165bf2574594509756ba77856bc0 to your computer and use it in GitHub Desktop.
Using separated babel config for server and client in Nextjs
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
{ | |
"presets": ["node8"], | |
"plugins": [ | |
["module-resolver", { | |
"root": ["."], | |
"alias": { | |
"~": "./server" | |
} | |
}] | |
] | |
} |
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 = { | |
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