一般情况下,“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/