在Linux下可以顺利编译Scratch3.0,但windows下经常会出各种各样的问题,建议使用windows的linux的环境(WSL)去编译scratch。
环境准备
- 开启WIN10的Linux子系统支持
控制面板->应用->程序和功能->启用或关闭Windows功能
勾选”适用于Linux的Windows子系统”
确定,重启 - 应用商店搜索安装Ubuntu
-
进入ubuntu
-
下载nodejs源码
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
-
安装nodejs
apt-get install -y nodejs
-
升级npm
npm install -g npm
Tips: 如果使用VS Code,可以安装Remote – WSL插件,一键连接到win10的子系统
编译scratch
- 拉取最新代码
git clone https://github.com/LLK/scratch-gui.git
- 安装依赖
cd scratch-gui
npm i
如果卡死,尝试按Enter键,或Ctrl+C终止并重新执行npm install安装
- 开始编译
npm run build
编译成功,build文件夹下就是编译好的scratch3.0了
二次开发scratch其他模块
比如要修改scratch-vm模块
- 克隆模块到本地
git clone https://github.com/LLK/scratch-vm.git
-
编译模块并将模块连接到全局
cd scratch-vm
npm i
npm run build
npm link
- 切换到Scratch-gui并引入模块
npm link scratch-vm
- 重新编译scratch-gui
npm run build
压缩代码
由于编译出来的js太大(20MB左右),加载十分慢,建议nginx开启gzip压缩,可以压缩至4~5MB。nginx gzip部分配置如下
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 4;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
开源版二次开发scratch3.0
Scratch3.0二次开发版,封装了常用的功能,开封即用。
https://github.com/open-scratch/scratch3
scratch开发者群,相关资源及软件可在群内下载
244050817
244051003 (已满)
发表评论
抢沙发~