webpack 4 执行 webpack hello.js hello.bundle.js
报错:
ERROR in multi ./hello.js hello.bundle.js
Module not found: Error: Can't resolve in 'hello.bundle.js' in 'F:\git\webpack-demo'
@ multi ./hello.js hello.bundle.js
webpack 4如何在命令行中执行 hello.js 打包到hello.bundle.js?
webpack 4 之后这个命令已经不行,需要命令行指明output-filename 和 output-path
npx webpack hello.js --output-filename hello.bundle.js --output-path . --mode development
非常感谢
视频讲的是webpack3.0的版本,可能你本地的是webpack4.0的版本,webpack hello.js hello.bundle.js 这个执行语句在4.0中已经不能用了,所以你要使用npx webpack hello.js --output-filename hello.bundle.js --output-path . --mode development
好了,就是不知道如何重新打包的命令是什么。。。。 再次打包就报错了。不过只看到第一节,后面应该会讲到。
我尝试了很多,都报错,不过可以安装版本就可以了
很可能路径错了
pageage.json
{
"name": "webpack4",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode production",
"dev": "webpack --mode development"
},
"author": "",
"license": "ISC",
"dependencies": {
"webpack": "^4.1.1"
},
"devDependencies": {
"webpack-cli": "^2.0.12"
}
}webpack.config.js
const path = require('path');
module.exports = {
entry: './src/javascript/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname,'dist')
}
}文件目录
