liuying525
2023-02-16 11:42
webpack5的小伙伴,报错看这里,我解决了。下面引入的模块都需要自己手动去安装以下,其中process/browser,这是两个,分开装。
const path = require("path");
const nodeExcternals = require("webpack-node-externals");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const webpackconfig = {
target: "node",
mode: "development",
entry: {
server: path.join(__dirname, "index.js"),
},
output: {
filename: "[name].bundle.js",
path: path.join(__dirname, "./dist"),
},
devtool: "eval-source-map",
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: {
loader: "babel-loader",
},
exclude: [path.join(__dirname, "/node_modules")],
},
],
},
externals: [nodeExcternals()],
plugins: [new CleanWebpackPlugin()],
node: {
global: true,
__filename: true,
__dirname: true,
},
resolve: {
fallback: {
console: require.resolve("console-browserify"),
process: require.resolve("process/browser"),
buffer: require.resolve("buffer"),
path: require.resolve("path-browserify"),
setImmediate: require.resolve("setimmediate"),
},
},
};
module.exports = webpackconfig;
还没有人回答问题,可以看看其他问题
6大角度 开拓前端进阶之路
922 学习 · 0 问题