babeljs - 在 .babelrc 文件中指定 cacheDirectory

标签 babeljs

我试过了:

{
    "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: Default false. 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') or true (loader: babel-loader?cacheDirectory=true) the loader will use the default cache directory in node_modules/.cache/babel-loader or fallback to the default OS temporary file directory if no node_modules folder could be found in any root directory.

关于babeljs - 在 .babelrc 文件中指定 cacheDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47936856/

相关文章:

javascript - ES6 单元测试——导入和导出模块

javascript - 无法通过unpkg使用MATERIAL-UI和React

node.js - ES6 方法得到一个空值 "this"并且类变量不可访问

javascript - 可选的链接运算符在将我的应用程序构建到 Heroku 时给出 SyntaxError 但在我的机器上工作

reactjs - 在新的 CRA 中使用 babel 转译包后 CSS 和图像文件不会出现

javascript - 为 Material.io 设置环境的资源?

javascript - 如何忽略 Istanbul 尔覆盖率报告中的函数 _interopRequireDefault?

javascript - 语法错误 : Unexpected identifier with mocha and babel

babeljs - 由于@babel/preset-typescript,Treeshaking webpack 4 不适用

reactjs - React 应用程序可以在没有构建系统的情况下在不同的 JS 文件中包含组件吗?