webpack输出文件名配置不工作

jgwigjjp  于 2023-04-21  发布在  Webpack
关注(0)|答案(2)|浏览(182)

当我运行“npx webpack --config webpack.config.js”时,即使我将其配置为“bundle.js”,它仍然会在dist文件夹中生成“main.js”,并且控制台会显示:
asset main.js 0 bytes [compared for emit] [minimized](name:main)./src/index.js 1字节[构建] [代码生成]
配置中的警告尚未设置“mode”选项,webpack将回退到“production”以获取此值。将“mode”选项设置为“development”或“production”以启用每个环境的默认值。您也可以将其设置为“none”以禁用任何默认行为。了解更多信息:https://webpack.js.org/configuration/mode/
webpack 5.24.4编译时在167毫秒内出现1个警告
我当前的文件结构:

/root
 /dist
 /src
  index.js
 /node_modules
 package.json
 package-lock.json
 webpack.config.js

package.json:

{
  "name": "mydemo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  },
  "devDependencies": {
    "webpack": "^5.24.4",
    "webpack-cli": "^4.5.0"
  }
}

webpack.config.js:

const path = require('path')

module.exports = {
  entry: path.resolve(__dirname, 'src', 'index.js'),
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  }
}
0yg35tkg

0yg35tkg1#

原来是我不熟悉vscode,当我编辑所有的配置文件时,我没有保存,所以我猜构建器只是采取了上次的配置并运行它。

628mspwn

628mspwn2#

这个问题仍然发生在2022-04-20使用webpack 5.80.0。无论我对entry[name]做什么,它总是生成dist\main.js而不是dist\bundle.js。这让我抓狂!

相关问题