我可以使用 webpack 生成的构建命令删除/忽略文件吗?

发布于 2025-01-12 21:05:10 字数 1002 浏览 0 评论 0原文

我正在使用 wp-scripts 包 生成一些文件。 wp-scripts 内部使用 webpack。该项目是使用 React 创建的,并使用模块化 css。

package.json

"scripts": {
    ...
    "build": "wp-scripts build src/index.js src/save.js",
    ...
}

我的 package.json 构建命令为每个入口点创建 3 个文件。

当前输出

  • index.asset.php
  • index.js
  • index.css
  • save.asset.php
  • save.js
  • save.css

仅需要save.js文件的css文件。我不想要构建中的其他 2 个文件。

所需输出

  • index.asset.php
  • index.js
  • index.css
  • save.css

问题

所以我想删除2个特定文件。

有人可以解释一下如何:

  • 不在构建命令中生成这两个文件(首选方法)
  • 在使用构建命令构建这两个文件后删除它们

注意:目前我可以手动删除这些文件或保留它们。不会对项目造成太大影响。但我宁愿让它自动化,因为我可能会忘记删除文件并使构建变得比必要的更大。

I am using the wp-scripts package to generate some files. Internally wp-scripts uses webpack. The project is created using React and uses modular css.

package.json

"scripts": {
    ...
    "build": "wp-scripts build src/index.js src/save.js",
    ...
}

My package.json build command creates 3 files for every entry point.

current output

  • index.asset.php
  • index.js
  • index.css
  • save.asset.php
  • save.js
  • save.css

Only the css file of the save.js file is necessary. I don't want the other 2 files in the build.

desired output

  • index.asset.php
  • index.js
  • index.css
  • save.css

The question

So I want to remove 2 specific files.

Can someone explain how to:

  • not generate these 2 files in the build command ( preferred approach )
  • remove these 2 files after building them using the build command

NOTE: Currently I can either remove the files manually or keep them. It won't affect the project much. But I'd rather have it automated as I will probably forget to remove the files and make the build bigger than necessary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文