新建小游戏,选的飞机游戏那个模板。
project.config.json文件内容
{
"description": "项目配置文件。",
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": false,
"newFeature": true,
"nodeModules": true,
"autoAudits": false
},
"compileType": "game",
"libVersion": "2.6.2",
"appid": "wx96df41d3b939af83",
"projectname": "pet",
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
执行 npm install pixi.js --save安装了 pixi.js库,顺便把pixi.js从node_modules里面拷贝到js/libs目录下一份。
game.js中引入pixi.js
1. const PIXI = require('pixi.js') //报错 module "pixi.js" is not defined
2. const PIXI = require('./node_modules/pixi.js/dist/pixi') //报错 module "./node_modules/pixi.js/dist/pixi" is not defined
3. const PIXI = require('./js/libs/pixi') //这么引用完全正确的,可运行。
4. import * as PIXI from './node_modules/pixi.js/dist/pixi' //报错 module "./node_modules/pixi.js/dist/pixi" is not defined
5. import * as PIXI from './js/libs/pixi' //正常运行
问题:
小游戏里面不能直接 require node_modules(通过npm install)下的库么?node_modules这个文件夹有什么特殊么?
但是我看文档说是可以的啊,说是支持commonjs方式啊?我哪里操作的不对么?
希望有人能给与指导一下。
有执行npm构建吗?