gpt4 book ai didi

javascript - 使用webpack时如何移动 "index.html"?

转载 作者:太空宇宙 更新时间:2023-11-04 02:10:27 24 4
gpt4 key购买 nike

一般情况下,“index.html”会在什么时候使用webpack加载?

我想将“index.html”移至 build/中。

我在使用 webpack 的 npm start 的数据流方面遇到了麻烦。

在package.json中,“start”定义为:

"node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js".

但是,我找不到它会从“webpack-dev-server.js”跳转到哪里。

我在其中找到了两个关于“index.html”的描述,如下:

     .boolean("history-api-fallback").describe("history-api-fallback", "Fallback to /index.html for Single Page Applications.")

    console.log("404s will fallback to %s", options.historyApiFallback.index || "/index.html");

当我尝试将“index.html”移动到 build/中时,浏览器返回“无法获取错误”。

“index.html”和 webpack.config.js 现在位于同一文件夹中。

    ./  index.html  package.json  src/    test/
../ build/ node_modules/ public/ style/
webpack.config.js

最佳答案

一种方法是更新脚本(在 package.json 中),以便将 index.html 复制到目标文件夹:

"scripts": {
"start": "node node_modules/.bin/webpack-dev-server --content-base src",
"build": "node node_modules/.bin/webpack && cp src/index.html build/index.html"
}

npm run build 现在还应该将 src/index.html 复制到 build/index.html

关于javascript - 使用webpack时如何移动 "index.html"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42499327/

24 4 0
文章推荐: python - 在 Python 中解析 Elasticsearch json 输出
文章推荐: jquery - 我想在向下滚动期间修复
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com