Skip to content

Instantly share code, notes, and snippets.

@saitonakamura
Last active April 16, 2018 07:19
Show Gist options
  • Save saitonakamura/72a658ce7790a99d81d35091c305dfb8 to your computer and use it in GitHub Desktop.
Save saitonakamura/72a658ce7790a99d81d35091c305dfb8 to your computer and use it in GitHub Desktop.
Next.js Awesome Typescript integration: how to add babel integration
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