我正在尝试编译此命令
npm run dev-server
我有这些文件
index.js
import otherSquare, { addNumber, name } from './utilities';
import otherScream from './scream';
console.log('index.js');
console.log(addNumber(30, 3));
console.log(name);
console.log(otherScream(name));
console.log(otherSquare(10));
webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public/scripts'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
}
]
},
devServer: {
contentBase: path.resolve(__dirname, 'public'),
publicPath: '/scripts/'
}
};
package.json
{
"name": "boilerplate",
"version": "1.0.0",
"description": "",
"main": "input.js",
"scripts": {
"dev-server": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"webpack-dev-server": "^3.9.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"live-server": "^1.2.1",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14"
}
}
当我在下面向下运行命令行时
npm run dev-server
我的网站正在运行,当我保存一些文件时,它会在页面上刷新,但是当我打开浏览器控制台时,会出现此错误
答案 0 :(得分:0)
我在终端中写了这个命令行
npm install webpack@latest webpack-cli@latest webpack-dev-server@latest
现在就可以了