node-formidable/formidable

Cannot find module 'xxx/plugins/octetstream.js' when use webpack for packaging

ching2018 opened this issue · 1 comments

webpack.config.js:

const path = require("path");
const NodemonPlugin = require("nodemon-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const { NormalModuleReplacementPlugin } = require("webpack");
module.exports = {
  entry: "./server/server.js",
  target: "node",
  plugins: [
    new NodemonPlugin(),
    new NormalModuleReplacementPlugin(
      /^hexoid$/,
      require.resolve("hexoid/dist/index.js")
    ),
  ],
  output: {
    path: path.resolve(__dirname, "server"),
    filename: "index.js",
    libraryTarget: "commonjs2",
  },
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"],
          },
        },
      },
    ],
  },
  optimization: {
    minimizer: [new TerserPlugin({ terserOptions: { mangle: false } })],
  },
};

server.js:

const fs = require("fs");
const path = require("path");
const os = require("os");
const Koa = require("koa2");
const koaBody = require("koa-body");
const KoaStatic = require("koa-static");
const cors = require("@koa/cors");
const { historyApiFallback } = require("koa2-connect-history-api-fallback");
const router = require("./router");

const platform = os.platform();
const app = new Koa();

app.use(historyApiFallback({ whiteList: ["/api"] }));
app.use(KoaStatic("./dist"));
app.use(
  koaBody({
    multipart: true,
    formidable: {
      maxFileSize: 2000 * 1024 * 1024,
      uploadDir:
        platform == "darwin"
          ? `/app.nw/`
          : `./`,
      keepExtensions: true,
    },
  })
);
app.use(router.routes());

console.log("SERVER_PORT", process.env.SERVER_PORT);
app.listen(process.env.SERVER_PORT || 3000);

Maybe it is an issue in koa-body