dist
- bundle.js
public
- index.css
- index.html
src
- index.js
以及下面的webpack配置。
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: "./src/index.js",
mode: "development",
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: { presets: ["@babel/env"] }
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
resolve: { extensions: ["*", ".js"] },
output: {
path: path.resolve(__dirname, "dist/"),
publicPath: "/dist/",
filename: "bundle.js"
},
devServer: {
contentBase: path.join(__dirname, "public/"),
port: 3000,
publicPath: "http://localhost:3000/dist/",
hotOnly: true
},
plugins: [new webpack.HotModuleReplacementPlugin()]
};
问题是,我的
.gitignore
dist
目录在其中,仅仅因为一个教程说这是最佳实践。
我使用
webpack --mode production
.
gh-pages
尽可能减少变化。理想情况下,我只想
追踪
master
,但也许这是不可能的。
Github页面自动服务
index.html
位于根目录,所以有一些问题。
-
距离
bundle.js
推到
gh页
.
-
index.html索引
是在
public
gh页
找不到。
-
index.html索引
../dist/bundle.js
根本不存在
bundle.js包
index.html索引
,但这似乎非常低效。有没有更好的方法来部署用webpack构建的静态网站
gh页
?