LayaBox2.4配置VsCode编译及运行环境
前言
Laya2.4
取消了内置VsCode
编辑器,现在代码编辑需要在单独的代码编辑器里面写,推荐使用VsCode
。发现不少同学无法运行启动调试了。这篇博客就是讲述如何配置编译及调试环境。
添加VsCode启动文件
以前启动文件是通过.laya
启动,不过现在在VsCode
需要在.vscode
中配置一个launch.json
。这里需要确保VsCode
安装了Debugger for Chrome
插件。
点击查看代码
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "chrome调试", "type": "chrome", "request": "launch", "file": "${workspaceRoot}/bin/index.html", // "换成自己的谷歌安装路径,": 比如 //window 默认安装路径为: "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" //mac 系统上的默认安装路径为 "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; // "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", "runtimeArgs": [ "--allow-file-access-from-files", "--allow-file-access-frome-files", " --disable-web-security" ], "sourceMaps": true, "webRoot": "${workspaceRoot}", //假如谷歌调试报userDataDir不可用,请把谷歌安装路径取得管理员权限,或者更换${tmpdir}为其他可以读写的文件夹,也可以删除。 "userDataDir": "${workspaceRoot}/.laya/chrome", "sourceMapPathOverrides": { "src/*": "${workspaceRoot}/src/*" } } ] }
配置编译文件
如果我们工程代码选择的是TypeScript
需要将ts
编译到js
再执行。这里使用VsCode
我们就不选用Laya
默认编译文件。
1.初始化工程文件npm init
跟着提示初始化完成
2.依次安装gulp
、rollup
、rollup-plugin-typescript2
、rollup-plugin-glsl
点击查看代码
npm install gulp --save-dev npm install rollup --save-dev npm install rollup-plugin-typescript2 --save-dev npm install rollup-plugin-glsl --save-dev
3.配置编译文件在项目根目录下新建gulpfile.js
文件
点击查看代码
const rollup = require("rollup"); const typescript = require('rollup-plugin-typescript2');//typescript2 plugin const glsl = require('rollup-plugin-glsl'); function dev(cb){ return rollup.rollup({ input:'./src/Main.ts', treeshake: true,//建议忽略 plugins: [ typescript({ check: false, //Set to false to avoid doing any diagnostic checks on the code tsconfigOverride:{compilerOptions:{removeComments: true}} }), glsl({ // By default, everything gets included include: /.*(.glsl|.vs|.fs)$/, sourceMap: false, compress:false }), /*terser({ output: { }, numWorkers:1,//Amount of workers to spawn. Defaults to the number of CPUs minus 1 sourcemap: false })*/ ] }).then(bundle => { bundle.write({ file: './bin/js/bundle.js', format: 'iife', name: 'laya', sourcemap: true }).then(()=>{ return cb(); }); }); } module.exports.dev = dev;
注意:rollup
模块只适用es6
,如果编译报错需要修改tsconfig.json
将module
字段修改为es6
至此我们可以在终端输入:gulp dev
编译typescript
之后运行即可。
也可以在package
配置对应执行代码,例如编译我们取名dev
可以在scripts
字段配置即可以通过npm run dev
执行编译
因为项目开始之后很少再配置项目编译等等,备下来预防以后忘记了。记录一下下!!
分类:
layabox
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧