Last active
April 16, 2018 07:20
-
-
Save saitonakamura/5e759a996488feece8319bd2652eb739 to your computer and use it in GitHub Desktop.
Next.js Awesome Typescript integration: how to add caching
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, options) { | |
const { dir, defaultLoaders } = options | |
config.pageExtensions.push(".ts", ".tsx"); | |
config.resolve.extensions.push(".ts", ".tsx"); | |
// 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", | |
options: { | |
useBabel: true, | |
babelOptions: fixBabelConfig, | |
// ADDED CACHING | |
useCache: true, | |
cacheDirectory: "node_modules/.cache/awesome-typescript-loader", | |
}, | |
}, | |
], | |
}); | |
return config; | |
} | |
} | |
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