@wordpress/scripts 添加自定义js文件抛出错误

@wordpress/scripts adding custom js files throws error

我在主题中使用@wordpress/scripts 来编译和压缩javascript 和scss。如果我使用默认的东西,一切都很好。但我想添加 2 个自定义 javascript 文件。但是当我这样做时它会抛出这个错误:

[webpack-cli] Unknown command or entry 'index=./src/index.js'

这就是我的 package.json 文件的样子:

{
 "name": "base-theme",
 "version": "1.0.0",
 "description": "Main File for WP theme",
 "repository": {},
 "license": "UNLICENSED",
 "dependencies": {
   "uuid": "^8.3.0"
 },
 "devDependencies": {
    "@types/react": "^16.9.47",
    "@wordpress/scripts": "^18.0.0",
    "autoprefixer": "^9.7.3",
    "browser-sync": "^2.27.5",
    "browser-sync-webpack-plugin": "^2.3.0",
    "copy-webpack-plugin": "^6.0.3",
    "css-loader": "^2.1.1",
    "extract-loader": "^3.1.0",
    "file-loader": "^3.0.1",
    "livereload": "^0.9.3",
    "node-sass": "^6.0.1",
    "postcss": "^8.1.0",
    "postcss-loader": "^3.0.0",
    "postcss-preset-env": "^6.6.0",
    "prettier": "^1.13.0",
    "sass-loader": "^8.0.2",
    "style-loader": "^1.1.2",
    "typescript": "^2.8.0",
    "webpack": "^5.0.0"
  },
  "stylelint": {
    "extends": "stylelint-config-recommended"
  },
  "scripts": {
    "start": "wp-scripts start",
    "build": "wp-scripts build src/index.js src/index-admin.js"
  }
}

所以当我 运行ning "npm 运行 build"

时会抛出错误

而且我已经尝试 google 分配,并且还尝试添加一个输出文件夹。但没有任何帮助。

因此,经过更多研究并在 Wordpress 论坛上发帖后,我得到了答案,这是 @wordpress/scripts@18.0.0 的已知问题。有了它的公开票:你可以在这里看到票:https://github.com/WordPress/gutenberg/pull/34264

如果我降级到 @wordpress/scripts@17.1.0 一切正常。因此,如果其他人遇到此问题,请先查看他们是否已解决问题,然后再寻找其他问题。