我正在尝试通过教程进行简单的Webpack配置。我的Web Pack配置文件如下所示:
import path from "path";
export default {
debug: true,
devtool: "inline-source-map",
noInfo: false,
entry: [path.resolve(__dirname, "src/index")],
target: "web",
output: {
path: path.resolve(__dirname, "src"),
publicPath: "/",
filename: "bundle.js",
},
plugins: [],
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loaders: ["babel"] },
{ test: /\.css$/, loaders: ["style", "css"] },
],
},
};
但是,当我运行程序时,出现以下错误消息:
(node:8944) ExperimentalWarning: The ESM module loader is experimental.
file:///C:/Users/G-L%20SYSTEMS/Desktop/js-dev-env-demo/webpack.config.dev.js:7
entry: [path.resolve(__dirname, "js--demodev-env/src/index")],
^
***ReferenceError: __dirname is not defined***
at file:///C:/Users/G-L%20SYSTEMS/Desktop/js-dev-env-demo/webpack.config.dev.js:7:24
at ModuleJob.run (internal/modules/esm/module_job.js:139:37)
at Loader.import (internal/modules/esm/loader.js:179:24)
ERROR: "open:src" exited with 1.
请帮忙吗?