Last active
April 16, 2018 07:19
-
-
Save saitonakamura/72a658ce7790a99d81d35091c305dfb8 to your computer and use it in GitHub Desktop.
Next.js Awesome Typescript integration: how to add babel integration
This file contains hidden or 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, options) { | |
const { dir, defaultLoaders } = options | |
config.pageExtensions.push(".ts", ".tsx"); | |
config.resolve.extensions.push(".ts", ".tsx"); | |
// ADDED THIS | |
// cacheDirectory option is unavailable in case of useBabel option | |
const fixBabelConfig = omit(defaultLoaders.babel.options, [ | |
"cacheDirectory", | |
]); | |
config.module.rules.push({ | |
test: /\.tsx?$/, | |
include: [dir], | |
exclude: /node_modules/, | |
use: [ | |
{ | |
loader: "awesome-typescript-loader", | |
// AND ADDED THIS | |
options: { | |
useBabel: true, | |
babelOptions: fixBabelConfig, | |
}, | |
}, | |
], | |
}); | |
return config; | |
} | |
} | |
// ALSO ADDED THIS | |
const omit = (obj, keysToOmit) => | |
Object.keys(obj) | |
.filter(key => keysToOmit.indexOf(key) < 0) | |
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment