我试过了:
{
"env": {
"development": {
"option": {
"cacheDirectory": true
}
}
}
}
但它没有用。我只想在开发环境中启用 cacheDirectory
以获得更快的 hmr。有任何想法吗?谢谢!
最佳答案
cacheDirectory
实际上是 babel-loader
的一个选项,而不是 babel
本身,所以 babelrc
的配置是不是此选项的正确位置。
你可以在babel-loader
的配置中开启它。一种方法是使用 loader: 'babel-loader?cacheDirectory'
。
来自 babel-loader
docs (强调我自己的):
This loader also supports the following loader-specific option:
cacheDirectory
: Defaultfalse
. When set, the given directory will be used to cache the results of the loader. Future webpack builds will attempt to read from the cache to avoid needing to run the potentially expensive Babel recompilation process on each run. If the value is blank (loader: 'babel-loader?cacheDirectory'
) ortrue
(loader: babel-loader?cacheDirectory=true
) the loader will use the default cache directory innode_modules/.cache/babel-loader
or fallback to the default OS temporary file directory if nonode_modules
folder could be found in any root directory.
关于babeljs - 在 .babelrc 文件中指定 cacheDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47936856/