简体   繁体   English

webpack构建脚本错误

[英]webpack build script error

i'm trying to start my local development environment with webpack and faced a problem with this scripts part 我正在尝试使用webpack启动本地开发环境,并且遇到了此脚本部分的问题

"scripts": {
    "start": "npm run build",
    "build": "webpack -d && copy /src/index.html /dist/index.html && webpack-dev-server --content-base src/ --inline",
    "build:prod": "webpack -p && copy /src/index.html dist/index.html"
  },

when i'm doing npm start I see 2 errors like this 当我在做npm start时,我会看到2个这样的错误

在此处输入图片说明

and one more with just npm run build failed what can be the reason for these errors ? 还有一个仅用npm run build失败的原因是什么?

index.html exist at provided address index.html存在于提供的地址

i though mb i missed something on my dependencies, but everything seems to on place 我虽然mb我错过了一些依赖我的东西,但一切似乎都到位了

  "dependencies": {
    "body-parser": "^1.18.2",
    "express": "^4.16.1",
    "oracledb": "^1.13.1",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "socket.io": "^2.0.3"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "webpack": "^3.6.0",
    "webpack-dev-server": "^2.9.1"
  }

The relevant error is: 相关的错误是:

The syntax of the command is incorrect.

As you're chaining multiple commands, you should generally isolate them and test them individually to see which one fails, but because it's right after the webpack build output, it must be the second one. 当链接多个命令时,通常应该隔离它们并分别测试它们,以查看哪个失败,但是由于它紧接在webpack构建输出之后,因此它必须是第二个。

copy /src/index.html /dist/index.html

copy is a Windows command and on Windows the command-line options start with a / instead of a - like on Unix. copy是Windows命令,在Windows上,命令行选项以/开头,而不是-在Unix上。 You're trying to use Unix style paths, which end up being recognised as options. 您正在尝试使用Unix样式路径,该路径最终被视为选项。 Paths on Windows use \\ (backslash) instead of / (forward slash). Windows上的路径使用\\ (反斜杠)代替/ (正斜杠)。 Even if it were Unix, you don't want to start the path with a / , because that would look in the root of your file system, not the current directory, and it would fail because it can't find the file, unless you coincidentally have such a file in the root of your file system. 即使是Unix,您也不想使用/开头路径,因为它会在文件系统的根目录(而不是当前目录)中查找,并且由于找不到文件而失败,除非您恰巧在文件系统的根目录中有这样的文件。

The command should be: 该命令应为:

copy src\index.html dist\index.html

This won't work on other operating systems and it's an additional step in the build system. 这在其他操作系统上将不起作用,这是构建系统中的附加步骤。 As an alternative you can integrate it into webpack with the copy-webpack-plugin , or in your specific case you can let webpack generate the index.html for you with the html-webpack-plugin . 作为替代方案,您可以使用copy-webpack-plugin将其集成到webpack中,或者在特定情况下,可以让webpack使用html-webpack-plugin为您生成index.html An advantage of the html-webpack-plugin is that it automatically inserts <script> tags with the produced bundles (especially useful if you use hashes in your bundle names). html-webpack-plugin的优点在于,它会自动将<script>标记与生成的包一起插入(如果在包名称中使用散列,则特别有用)。 This means that webpack would output everything you need for you application and you could just deploy your dist directory. 这意味着webpack将输出应用程序所需的一切,并且您只需部署dist目录即可。 As a bonus, it plays nicely with webpack-dev-server , so everything can be kept in memory and you don't need to generate the file beforehand to make it work. 另外,它可以与webpack-dev-server很好地配合使用,因此所有内容都可以保留在内存中,并且无需事先生成文件即可使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM