我安装了webpack-dev-server,在构建项目时没有错误,服务器成功启动,但是在浏览器控制台中,它剔除了这样的错误“未捕获的错误:找不到模块” dev,尝试加载时index.html,服务器返回main.js文件我不明白是什么问题,请帮忙!
webpack.config.js
module.exports = {
entry: './main',
mode: 'development',
output: {
filename: 'bundle.js'
},
module: {
rules: [
{ test: /\.js$/, loader: "babel-loader" }
]
},
watch:true
};
package.json
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"gsap": "^2.1.3",
"howler": "^2.1.2",
"pixi.js": "^5.0.3"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"babel-loader": "^8.0.6",
"i": "^0.3.6",
"npm": "^6.9.0",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4",
"webpack-dev-middleware": "^3.7.0",
"webpack-dev-server": "^3.7.1"
}
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<link rel="stylesheet" href="./main.css">
<body>
</body>
<script src="./dist/bundle.js"></script>
</html>
main.js
let PIXI = require('pixi.js');
let HOWLER = require('howler');
import TimeLineMax from 'gsap/TimelineMax';
const log = console.warn;
let doc = document;
//Aliases
let Application = PIXI.Application,
loader = PIXI.Loader.shared,
resources = PIXI.Loader.resources,
Sprite = PIXI.Sprite,
Container = PIXI.Container,
Howl = HOWLER.Howl,
Graphics = PIXI.Graphics;
//constants
const WIDTHCARDPLACE = 200;
const HEIGHTCARDPLACE = 300;
let app = new Application({
width: window.innerWidth,
height: window.innerHeight,
antialias: true
});
app.renderer.backgroundColor = 0xFFFFFF;
app.renderer.view.style.position = "absolute";
app.renderer.view.style.display = "block";
app.renderer.autoResize = true;
app.renderer.resize(window.innerWidth, window.innerHeight);
doc.body.appendChild(app.view);
setup.sprites = {};
const bottomPanel = new Container();
loader
.add("images/background.jpg", (resource) => {
const background = new Sprite(resource.texture);
app.stage.addChild(background);
})
.add("images/button_nachat.png", (resource) => {
const beginBtn = new Sprite(resource.texture);
beginBtn.position.set(0, 0);
beginBtn.buttonMode = true;
beginBtn.interactive = true;
//handler on the button start
beginBtn.on('pointerdown', function (e) {
});
bottomPanel.addChild(beginBtn);
}).load(setup);
//all downloads are complete
function setup() {
//add sprites to stage
/* for (const key in setup.sprites) {
app.stage.addChild(setup.sprites[key]);
}*/
const countCards = 5;
let vxCardPlace = 0;
const containerCardPlace = new Container();
for (let i = countCards; i--;){
let cardPlace = new Graphics();
cardPlace.beginFill(0x000000);
cardPlace.drawRect(vxCardPlace, 0, WIDTHCARDPLACE, HEIGHTCARDPLACE);
vxCardPlace += 250;
cardPlace.endFill();
containerCardPlace.addChild(cardPlace);
}
bottomPanel.position
.set(app.view.width / 2 - bottomPanel.width / 2, app.view.height - bottomPanel.height - 5);
containerCardPlace.position
.set(app.view.width / 2 - containerCardPlace.width / 2, window.innerHeight / 2 - bottomPanel.height);
app.stage.addChild(containerCardPlace);
app.stage.addChild(bottomPanel);
let tl = new TimeLineMax();
let obj = {a:0};
let line = new Graphics();
line.lineStyle(4, 0xFFFFFF, 1);
app.stage.addChild(line);
//animation experiment
tl.to(obj, 0.8, {a:1, onUpdate: function(){
line.moveTo(0, 0);
line.lineTo(app.view.width, 0);
line.lineTo(app.view.width, Math.sqrt(app.view.height * obj.a));
line.lineTo(0, app.view.height * obj.a);
}});
getRandomCards(1, containerCardPlace);
}
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
//selects a random card
function getRandomCards (count, containerCards) {
const cardsArray = [];
for (let i = count; i--;){
let card = new Graphics();
card.beginFill(0x66CCFF);
card.lineStyle(4, 0xFF3300, 1);
card.drawRect
(containerCards.children[0].position.x, containerCards.children[0].position.y, WIDTHCARDPLACE - 4, HEIGHTCARDPLACE - 4);
card.endFill();
containerCards.addChild(card);
}
}