当我运行“npx webpack --config webpack.config.js”时,即使我将其配置为“bundle.js”,它也会在 dist 文件夹中继续生成“main.js”,并且控制台将显示:
资产 main.js 0 字节 [与 emit 相比] [最小化](名称:main) ./src/index.js 1 字节 [构建] [代码生成]
配置中的警告 'mode' 选项尚未设置,webpack 将回退到此值的 'production'。将“模式”选项设置为“开发”或“生产”以启用每个环境的默认值。您还可以将其设置为“无”以禁用任何默认行为。了解更多: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
包.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'
}
}