代码之家  ›  专栏  ›  技术社区  ›  Carpetfizz

将webpack生成的应用程序发布到Github页面

  •  0
  • Carpetfizz  · 技术社区  · 5 年前

    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 位于根目录,所以有一些问题。

    1. 距离 bundle.js 推到 gh页 .

    2. index.html索引 是在 public gh页 找不到。

    3. index.html索引 ../dist/bundle.js 根本不存在

    bundle.js包 index.html索引 ,但这似乎非常低效。有没有更好的方法来部署用webpack构建的静态网站 gh页 ?

    0 回复  |  直到 5 年前