【问题标题】:Create-react-app build files tilde ~ characterCreate-react-app 构建文件波浪号 ~ 字符
【发布时间】:2019-10-05 19:34:28
【问题描述】:

有没有办法在 create-react-app 构建 js 文件名中不使用波浪号?

在我的 create-react-app 上运行 npm run build 后,我在 /static/js/ 文件夹中获得了几个 runtime~main.[hash].js 文件。我的目标文件系统不允许文件或文件夹名称中包含波浪号字符。

我可以在某处更改配置以使用- 而不是波浪号输出runtime-main.[hash].js??

https://facebook.github.io/create-react-app/docs/production-build

【问题讨论】:

  • 我在\node_modules\react-scripts\config\webpack.config.js 中找到了new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]) - 我相信这是生成名称的地方。我可以改变这个吗?我认为我需要先弹出?

标签: reactjs sharepoint create-react-app


【解决方案1】:

在不弹出的情况下解决:

-在你的项目中安装脚本:npm install @rescripts/cli --save-dev

-在你的项目根目录下创建一个文件.rescriptsrc.js,并把下面的代码放在里面:

module.exports = config => {
    config.optimization.splitChunks.automaticNameDelimiter = '_';
    if (config.optimization.runtimeChunk) {
        config.optimization.runtimeChunk = {
            name: entrypoint => `runtime_${entrypoint.name}`
        };
    }
    return config;
};

在 package.json 的 sripts 部分添加一个新条目 "build-re": "rescripts build"

现在在运行 npm run build-re 时,它​​会在文件名中生成 _ 而不是 ~。

https://github.com/harrysolovay/rescripts

【讨论】:

  • 当我运行build-r 时,我得到'rescripts' is not recognized as an internal or external command,
  • 因为我又遇到了这个...运行它的命令是npm run-script build-re
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-04
  • 2019-06-25
  • 1970-01-01
  • 2018-09-09
  • 2019-08-03
  • 2010-10-24
相关资源
最近更新 更多